请通过浏览器功能收藏网页

spring4 的国际化支持如何配置 spring4技术

发布时间:2018-10-28 16:38:54  作者:本站编辑  来源:本站原创  浏览次数:
我有话说 | 分享 |
www.javainfo.com.cn 上干货 欢迎收藏

在springMVC里面使用国际化语言支持,我们需要使用的到 jstl技术的 fmt 格式化支持。


那么如何配置呢, 看下面实际配置:

1) 添加JSTL的支持    添加以来jar包    共有两个

      1 jstl 

      2 stand

    作用,当我们使用JSP视图技术的时候, 添加JSTL的包后, 系统会自动将其解释为 jstl视图技术,对JSTL添加提供支持。

2)编写控制器跳转函数

   

     @RequestMapping("/jstl")

public String testViewAndViewResolver(){

System.out.println("calling jstl ");

return SUCCESS;

}

3)添加资源文件  暂时模拟 中文、英文两种情况, 文件直接放在根目录(src)下

    image.png

       内容如下:文件1--》

                        i18n.username=Username

                        i18n.password=Password

       内容如下:文件 2--》

                        i18n.username=Username

                        i18n.password=Password

        内容如下:文件3--》

                        i18n.username=\u7528\u6237\u540D

                        i18n.password=\u5BC6\u7801


4)配置springMVC i18n文件配置    

        <!-- 配置国际化资源文件 -->

<bean id="messageSource"

class="org.springframework.context.support.ResourceBundleMessageSource">

<property name="basename" value="i18n"></property>

</bean>

5)编辑JSP页面,调用i18n配置

    页面引入jstl fmt

   "<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>"

     页面调用i18n资源

    <fmt:message key="i18n.username"></fmt:message>

    <fmt:message key="i18n.password"></fmt:message>

6)测试情况 , 通过浏览器设置当前的语言环境, 刷新界面系统会根据当前的环境来展示文本内容


如有疑问 请留言 欢迎提供建议

评论已有 0