类 MessageSourceAccessor
- java.lang.Object
- org.springframework.context.support.MessageSourceAccessor
public class MessageSourceAccessor extends Object
Helper class for easy access to messages from a MessageSource, providing various overloaded getMessage methods.Available from ApplicationObjectSupport, but also reusable as a standalone helper to delegate to in application objects.
- 从以下版本开始:
- 23.10.2003
- 作者:
- Juergen Hoeller
- 另请参阅:
ApplicationObjectSupport.getMessageSourceAccessor()
构造器概要
构造器 构造器 说明 MessageSourceAccessor(MessageSource messageSource)
Create a new MessageSourceAccessor, using LocaleContextHolder's locale as default locale.MessageSourceAccessor(MessageSource messageSource, Locale defaultLocale)
Create a new MessageSourceAccessor, using the given default locale.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected Locale
getDefaultLocale()
Return the default locale to use if no explicit locale has been given.String
getMessage(String code)
Retrieve the message for the given code and the default Locale.String
getMessage(String code, Object[] args)
Retrieve the message for the given code and the default Locale.String
getMessage(String code, Object[] args, String defaultMessage)
Retrieve the message for the given code and the default Locale.String
getMessage(String code, Object[] args, String defaultMessage, Locale locale)
Retrieve the message for the given code and the given Locale.String
getMessage(String code, Object[] args, Locale locale)
Retrieve the message for the given code and the given Locale.String
getMessage(String code, String defaultMessage)
Retrieve the message for the given code and the default Locale.String
getMessage(String code, String defaultMessage, Locale locale)
Retrieve the message for the given code and the given Locale.String
getMessage(String code, Locale locale)
Retrieve the message for the given code and the given Locale.String
getMessage(MessageSourceResolvable resolvable)
Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance) in the default Locale.String
getMessage(MessageSourceResolvable resolvable, Locale locale)
Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance) in the given Locale.
构造器详细资料
MessageSourceAccessor
public MessageSourceAccessor(MessageSource messageSource)
Create a new MessageSourceAccessor, using LocaleContextHolder's locale as default locale.- 参数:
messageSource
- the MessageSource to wrap- 另请参阅:
LocaleContextHolder.getLocale()
MessageSourceAccessor
public MessageSourceAccessor(MessageSource messageSource, Locale defaultLocale)
Create a new MessageSourceAccessor, using the given default locale.- 参数:
messageSource
- the MessageSource to wrapdefaultLocale
- the default locale to use for message access
方法详细资料
getDefaultLocale
protected Locale getDefaultLocale()
Return the default locale to use if no explicit locale has been given.The default implementation returns the default locale passed into the corresponding constructor, or LocaleContextHolder's locale as fallback. Can be overridden in subclasses.
getMessage
public String getMessage(String code, String defaultMessage)
Retrieve the message for the given code and the default Locale.- 参数:
code
- code of the messagedefaultMessage
- String to return if the lookup fails- 返回:
- the message
getMessage
public String getMessage(String code, String defaultMessage, Locale locale)
Retrieve the message for the given code and the given Locale.- 参数:
code
- code of the messagedefaultMessage
- String to return if the lookup failslocale
- Locale in which to do lookup- 返回:
- the message
getMessage
public String getMessage(String code, Object[] args, String defaultMessage)
Retrieve the message for the given code and the default Locale.- 参数:
code
- code of the messageargs
- arguments for the message, ornull
if nonedefaultMessage
- String to return if the lookup fails- 返回:
- the message
getMessage
public String getMessage(String code, Object[] args, String defaultMessage, Locale locale)
Retrieve the message for the given code and the given Locale.- 参数:
code
- code of the messageargs
- arguments for the message, ornull
if nonedefaultMessage
- String to return if the lookup failslocale
- Locale in which to do lookup- 返回:
- the message
getMessage
public String getMessage(String code) throws NoSuchMessageException
Retrieve the message for the given code and the default Locale.- 参数:
code
- code of the message- 返回:
- the message
- 抛出:
NoSuchMessageException
- if not found
getMessage
public String getMessage(String code, Locale locale) throws NoSuchMessageException
Retrieve the message for the given code and the given Locale.- 参数:
code
- code of the messagelocale
- Locale in which to do lookup- 返回:
- the message
- 抛出:
NoSuchMessageException
- if not found
getMessage
public String getMessage(String code, Object[] args) throws NoSuchMessageException
Retrieve the message for the given code and the default Locale.- 参数:
code
- code of the messageargs
- arguments for the message, ornull
if none- 返回:
- the message
- 抛出:
NoSuchMessageException
- if not found
getMessage
public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException
Retrieve the message for the given code and the given Locale.- 参数:
code
- code of the messageargs
- arguments for the message, ornull
if nonelocale
- Locale in which to do lookup- 返回:
- the message
- 抛出:
NoSuchMessageException
- if not found
getMessage
public String getMessage(MessageSourceResolvable resolvable) throws NoSuchMessageException
Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance) in the default Locale.- 参数:
resolvable
- the MessageSourceResolvable- 返回:
- the message
- 抛出:
NoSuchMessageException
- if not found
getMessage
public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException
Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance) in the given Locale.- 参数:
resolvable
- the MessageSourceResolvablelocale
- Locale in which to do lookup- 返回:
- the message
- 抛出:
NoSuchMessageException
- if not found