springMVC-i18n&&theme实现之一
来源:互联网 发布:女孩穿衣打扮知乎 编辑:程序博客网 时间:2024/06/11 09:28
参考:
http://blog.csdn.net/rj042/article/details/23354225
http://www.cnblogs.com/chenying99/archive/2012/05/17/2505646.html实现前提:
1.国际化资源文件
2.拦截器(view到controller层,解析用户区域,封装数据到model,返回view层)
3.解析用户区域策略(底层操作系统一致 ,cookie ,session ,固定 ,自定义)
4.解析国际化资源文件(org.springframework.context.support.ReloadableResourceBundleMessageSource).
实现思路:
拦截器(LocaleChangeInterceptor)拦截请求,localeResolver解析用户区域,url映射到controller完成业务处理,封装数据到model,view(通过ReloadableResourceBundleMessageSource)解析<spring:message code="xxx" />标签,根据code值获取对应locale语言的资源项值,完成页面渲染.
实现方法:
mvc.xml:
<interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="lang" />
<interceptors>
<bean id="loacleResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" p:cookieName="locale" />
<bean id="messageResource" class="org.springframework.context.support.ReloadableResourceBundlerMessageResource" p:basenames="WEB-INF/i8n/message" p:fallbackToSystemLocale="false" />
html:
<span><spring:message code="xxx" /> </span>
注意:
web.xml每个org.springframework.web.servlet.DispatcherServlet,解析用户区域的策略唯一,bean的id为localeResolver.默认为AcceptRequestLocaleResolver(解析请求头accept-language:数据值为底层操作系统的locale.cookie值无法更改).
LocaleResolver静态方法setLocale可更改语言集locale.支持自定义localeResolver(实现org.springframework.web.servlet.LocaleResolver接口).
- springMVC-i18n&&theme实现之一
- springMVC-i18n&&theme实现之二
- Java SpringMVC实现国际化整合案例分析(i18n)
- Spring MVC+Freemarker+Javascript的多语言(国际化i18n/本地化)和主题(Theme)实现
- springMVC-多语言I18n
- SpringMvc国际化i18n
- springMVC项目中配置i18n
- i18n的实现
- Struts 实现的I18N
- JavaSE实现国际化(i18n)
- 初步实现 I18N 插件
- react i18n 实现国际化
- struts-i18n国际化实现
- Vue + i18n实现国际化
- I18n实现中英文切换
- springMVC之一
- eclipse color theme 问题之一
- SpringMVC国际化(i18n)(五)
- hdu 3032 Nim or not Nim? 博弈
- hdu_2028_Lowest Common Multiple Plus
- poj1703
- Deepin搭建Qt5开发环境
- Fast TileMap
- springMVC-i18n&&theme实现之一
- 算法训练 关联矩阵
- [LeetCode] String to Integer (atoi)
- js 进阶知识
- 1065. A+B and C (64bit) (20)
- poj 2586
- Extremal Region(极值区域)文本定位与识别法-学习笔记(二)
- cc: 内部错误:已杀死 (程序 cc1)
- c语言头文件