spring boot Locale Resolver默认西班牙语

时间:2017-01-04 20:40:56

标签: spring-boot locale

我找不到将Locale.US的默认语言环境更改为西班牙语的方法。它不在列表中,我找不到任何解释方法。

  

@Configuration   公共类SpringMvcConfiguration扩展了WebMvcConfigurerAdapter {

@Bean
public LocaleResolver localeResolver(){
    SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();
    sessionLocaleResolver.setDefaultLocale(Locale.US);

    return sessionLocaleResolver;

}

@Bean
LocaleChangeInterceptor localeChangeInterceptor(){
    LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
    localeChangeInterceptor.setParamName("lang");
    return localeChangeInterceptor;
}

@Override
public void addInterceptors(InterceptorRegistry interceptorRegistry){
    interceptorRegistry.addInterceptor(localeChangeInterceptor());
}

}

1 个答案:

答案 0 :(得分:0)

没有像Locale.US这样的常量来帮助你。但是您可以实例化一个新的Locale,传递new Locale("es")中正确的语言信息,如documentation中所述。或者使用Java 8中添加的Locale.Builder