springmvc国际化
生活随笔
收集整理的這篇文章主要介紹了
springmvc国际化
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
1、配置
?在spring配置文件中引入國際化
<!-- 定義國際化消息 --> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="messages"/> </bean> <!-- 獲取本地 --> <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"/> <mvc:interceptors> <!-- Changes the locale when a 'locale' request parameter is sent; e.g. /?locale=de --> <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" /> </mvc:interceptors>2、建立兩個文件messages_en.properties 和 messages_zh.properties,分別對應英文和中文
需注意中文配置文件
3、在jsp頁面中的使用
引入spring標簽
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 使用標簽進行國際化 <spring:message code="parentId"/>//parentId為配置文件中的key值 4、在java類里面的使用方式?先獲取HttpServletRequest request對象
RequestContext requestContext = new RequestContext(request);//獲取請求上下文對象Locale myLocale = requestContext.getLocale();//獲取locale對象System.out.println(myLocale);//得到國際化名稱zh_CN en_USSystem.out.println(requestContext.getMessage("name"));//通過key獲取國際化文件中的value?
轉載于:https://my.oschina.net/u/615618/blog/161638
總結
以上是生活随笔為你收集整理的springmvc国际化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WPF 的拖拽操作(DragDrop)
- 下一篇: iOS培训章节——C++函数的重载