接口 LocaleResolver
- 所有已知子接口:
LocaleContextResolver
- 所有已知实现类:
AbstractLocaleContextResolver
,AbstractLocaleResolver
,AcceptHeaderLocaleResolver
,CookieLocaleResolver
,FixedLocaleResolver
,SessionLocaleResolver
public interface LocaleResolver
Interface for web-based locale resolution strategies that allows for both locale resolution via the request and locale modification via request and response.This interface allows for implementations based on request, session, cookies, etc. The default implementation is
AcceptHeaderLocaleResolver
, simply using the request's locale provided by the respective HTTP header.Use
RequestContext.getLocale()
to retrieve the current locale in controllers or views, independent of the actual resolution strategy.Note: As of Spring 4.0, there is an extended strategy interface called
LocaleContextResolver
, allowing for resolution of aLocaleContext
object, potentially including associated time zone information. Spring's provided resolver implementations implement the extendedLocaleContextResolver
interface wherever appropriate.- 从以下版本开始:
- 27.02.2003
- 作者:
- Juergen Hoeller
- 另请参阅:
LocaleContextResolver
,LocaleContextHolder
,RequestContext.getLocale()
,RequestContextUtils.getLocale(javax.servlet.http.HttpServletRequest)
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 Locale
resolveLocale(HttpServletRequest request)
Resolve the current locale via the given request.void
setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale)
Set the current locale to the given one.
方法详细资料
resolveLocale
Locale resolveLocale(HttpServletRequest request)
Resolve the current locale via the given request. Can return a default locale as fallback in any case.- 参数:
request
- the request to resolve the locale for- 返回:
- the current locale (never
null
)
setLocale
void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale)
Set the current locale to the given one.- 参数:
request
- the request to be used for locale modificationresponse
- the response to be used for locale modificationlocale
- the new locale, ornull
to clear the locale- 抛出:
UnsupportedOperationException
- if the LocaleResolver implementation does not support dynamic changing of the locale