1.配置文件
2.页面引用:
3.语言切换页面:
4.切换controller:
<!-- load the properties file -->
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>messages</value>
</list>
</property>
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<!-- property name="defaultLocale" value="en"/> -->
</bean>
2.页面引用:
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<spring:message code="welcome"/>
3.语言切换页面:
<a href="/login/changeLocal.air?local=zh">中文</a>
<a href="/login/changeLocal.air?local=en">英文</a>
4.切换controller:
@RequestMapping
public ModelAndView changeLocal(HttpServletRequest request,String local,HttpServletResponse response){
if("zh".equals(local))
localeResolver.setLocale(request, response, Locale.CHINA);
else if("en".equals(local))
localeResolver.setLocale(request, response, Locale.ENGLISH);
return new ModelAndView("redirect:/login/login.air");
}