Spring中的LocaleResolver

Jot*_*thi 1 java spring spring-mvc internationalization

我正在为我的应用程序使用会话语言环境解析器.我在下拉列表中显示语言.如果用户选择任何一种语言,则重新填充该语言的所有值.

<property name="interceptors">
    <list>
        <ref bean="localeChangeInterceptor" />
    </list>
</property>

<bean id="localeChangeInterceptor"
      class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    <property name="paramName" value="languageCode" />
</bean>

<bean id="localeResolver"
      class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />
Run Code Online (Sandbox Code Playgroud)

但它并没有从会议中读到它.始终从浏览器设置中考虑默认语言.请帮忙.

Ral*_*lph 5

您需要以这种方式获取区域设置:

Locale loc=RequestContextUtils.getLocale(request);
Run Code Online (Sandbox Code Playgroud)

  • 如果使用@RequestMapping注释控制器方法,则只需向方法添加Locale参数,Spring就会自动为您提供.http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-arguments (5认同)