类 StaticMessageSource
- java.lang.Object
- org.springframework.context.support.MessageSourceSupport
- org.springframework.context.support.AbstractMessageSource
- org.springframework.context.support.StaticMessageSource
- 所有已实现的接口:
HierarchicalMessageSource
,MessageSource
public class StaticMessageSource extends AbstractMessageSource
Simple implementation ofMessageSource
which allows messages to be registered programmatically. This MessageSource supports basic internationalization.Intended for testing rather than for use in production systems.
- 作者:
- Rod Johnson, Juergen Hoeller
字段概要
从类继承的字段 org.springframework.context.support.MessageSourceSupport
logger
构造器概要
构造器 构造器 说明 StaticMessageSource()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
addMessage(String code, Locale locale, String msg)
Associate the given message with the given code.void
addMessages(Map<String,String> messages, Locale locale)
Associate the given message values with the given keys as codes.protected MessageFormat
resolveCode(String code, Locale locale)
Subclasses must implement this method to resolve a message.protected String
resolveCodeWithoutArguments(String code, Locale locale)
Subclasses can override this method to resolve a message without arguments in an optimized fashion, i.e. to resolve without involving a MessageFormat.String
toString()
从类继承的方法 org.springframework.context.support.AbstractMessageSource
getCommonMessages, getDefaultMessage, getDefaultMessage, getMessage, getMessage, getMessage, getMessageFromParent, getMessageInternal, getParentMessageSource, isUseCodeAsDefaultMessage, resolveArguments, setCommonMessages, setParentMessageSource, setUseCodeAsDefaultMessage
从类继承的方法 org.springframework.context.support.MessageSourceSupport
createMessageFormat, formatMessage, isAlwaysUseMessageFormat, renderDefaultMessage, setAlwaysUseMessageFormat
构造器详细资料
StaticMessageSource
public StaticMessageSource()
方法详细资料
resolveCodeWithoutArguments
@Nullable protected String resolveCodeWithoutArguments(String code, Locale locale)
从类复制的说明:AbstractMessageSource
Subclasses can override this method to resolve a message without arguments in an optimized fashion, i.e. to resolve without involving a MessageFormat.The default implementation does use MessageFormat, through delegating to the
AbstractMessageSource.resolveCode(java.lang.String, java.util.Locale)
method. Subclasses are encouraged to replace this with optimized resolution.Unfortunately,
java.text.MessageFormat
is not implemented in an efficient fashion. In particular, it does not detect that a message pattern doesn't contain argument placeholders in the first place. Therefore, it is advisable to circumvent MessageFormat for messages without arguments.- 覆盖:
resolveCodeWithoutArguments
在类中AbstractMessageSource
- 参数:
code
- the code of the message to resolvelocale
- the locale to resolve the code for (subclasses are encouraged to support internationalization)- 返回:
- the message String, or
null
if not found - 另请参阅:
AbstractMessageSource.resolveCode(java.lang.String, java.util.Locale)
,MessageFormat
resolveCode
@Nullable protected MessageFormat resolveCode(String code, Locale locale)
从类复制的说明:AbstractMessageSource
Subclasses must implement this method to resolve a message.Returns a MessageFormat instance rather than a message String, to allow for appropriate caching of MessageFormats in subclasses.
Subclasses are encouraged to provide optimized resolution for messages without arguments, not involving MessageFormat. See the
AbstractMessageSource.resolveCodeWithoutArguments(java.lang.String, java.util.Locale)
javadoc for details.- 指定者:
resolveCode
在类中AbstractMessageSource
- 参数:
code
- the code of the message to resolvelocale
- the locale to resolve the code for (subclasses are encouraged to support internationalization)- 返回:
- the MessageFormat for the message, or
null
if not found - 另请参阅:
AbstractMessageSource.resolveCodeWithoutArguments(String, java.util.Locale)
addMessage
public void addMessage(String code, Locale locale, String msg)
Associate the given message with the given code.- 参数:
code
- the lookup codelocale
- the locale that the message should be found withinmsg
- the message associated with this lookup code
addMessages
public void addMessages(Map<String,String> messages, Locale locale)
Associate the given message values with the given keys as codes.- 参数:
messages
- the messages to register, with messages codes as keys and message texts as valueslocale
- the locale that the messages should be found within