SpringMVC之国际化

springmvc国际化的准备工作:

1、在xml文件内进行配置

  

<!-- 存储区域设置信息 -->
    <bean id="localeResolver"
          class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />
    <!-- 国际化资源文件 -->
    <bean id="messageSource"
          class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
          p:basename="webp/WEB-INF/resource/messages"/>

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

2、增加配置文件以及在.jsp页面引入标签

 

  .properties文件

  messages_en_US.properties和messages_zh_CN.properties文件设置响应的key  value键值对

 

  页面文件

<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<spring:message code="language.cn" />

其中code即为properties文件中的key,不同的properties文件有不同的value值。
通过<spring:message />来获取响应的code对应的value
<spring:message code="operator"/>

转载于:https://www.cnblogs.com/xiaotieblog/p/8243471.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值