类 AcceptHeaderLocaleResolver
- java.lang.Object
- org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver
- 所有已实现的接口:
LocaleResolver
public class AcceptHeaderLocaleResolver extends Object implements LocaleResolver
LocaleResolverimplementation that simply uses the primary locale specified in the "accept-language" header of the HTTP request (that is, the locale sent by the client browser, normally that of the client's OS).Note: Does not support
setLocale, since the accept header can only be changed through changing the client's locale settings.- 从以下版本开始:
- 27.02.2003
- 作者:
- Juergen Hoeller, Rossen Stoyanchev
- 另请参阅:
ServletRequest.getLocale()
构造器概要
构造器 构造器 说明 AcceptHeaderLocaleResolver()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 LocalegetDefaultLocale()The configured default locale, if any.List<Locale>getSupportedLocales()Return the configured list of supported locales.LocaleresolveLocale(HttpServletRequest request)Resolve the current locale via the given request.voidsetDefaultLocale(Locale defaultLocale)Configure a fixed default locale to fall back on if the request does not have an "Accept-Language" header.voidsetLocale(HttpServletRequest request, HttpServletResponse response, Locale locale)Set the current locale to the given one.voidsetSupportedLocales(List<Locale> locales)Configure supported locales to check against the requested locales determined viaServletRequest.getLocales().
构造器详细资料
AcceptHeaderLocaleResolver
public AcceptHeaderLocaleResolver()
方法详细资料
setSupportedLocales
public void setSupportedLocales(List<Locale> locales)
Configure supported locales to check against the requested locales determined viaServletRequest.getLocales(). If this is not configured thenServletRequest.getLocale()is used instead.- 参数:
locales- the supported locales- 从以下版本开始:
- 4.3
getSupportedLocales
public List<Locale> getSupportedLocales()
Return the configured list of supported locales.- 从以下版本开始:
- 4.3
setDefaultLocale
public void setDefaultLocale(@Nullable Locale defaultLocale)
Configure a fixed default locale to fall back on if the request does not have an "Accept-Language" header.By default this is not set in which case when there is "Accept-Language" header, the default locale for the server is used as defined in
ServletRequest.getLocale().- 参数:
defaultLocale- the default locale to use- 从以下版本开始:
- 4.3
getDefaultLocale
@Nullable public Locale getDefaultLocale()
The configured default locale, if any.This method may be overridden in subclasses.
- 从以下版本开始:
- 4.3
resolveLocale
public Locale resolveLocale(HttpServletRequest request)
从接口复制的说明:LocaleResolverResolve the current locale via the given request. Can return a default locale as fallback in any case.- 指定者:
resolveLocale在接口中LocaleResolver- 参数:
request- the request to resolve the locale for- 返回:
- the current locale (never
null)
setLocale
public void setLocale(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable Locale locale)
从接口复制的说明:LocaleResolverSet the current locale to the given one.- 指定者:
setLocale在接口中LocaleResolver- 参数:
request- the request to be used for locale modificationresponse- the response to be used for locale modificationlocale- the new locale, ornullto clear the locale