ResourceBundleMessageSource

  org.springframework.context.support.ResourceBundleMessageSource
的复习,这个类主要提供国际化的支持。
1 在spring的配置文件中添加
  <bean id="messageSource"    class="org.springframework.context.support.ResourceBundleMessageSource">
                  <property name="basename" value="messages" />
 </bean>

2 添加资源文件 路径位于src下面

  2.1 messages_en_US.properties 和 messages_zh_CN.properties

        customer.name=fan wen bo, age : {0}, URL :{1}

3 测试

  java代码测试

   String name = apps.getMessage("customer.name",   
                 new Object[] { 28,"http://www.eeee.com" }, Locale.US);
   String name2 = apps.getMessage("customer.name",   
                 new Object[] { 28,"http://www.eeee.com" }, Locale.SIMPLIFIED_CHINESE);
   System.out.println(name);
   System.out.println(name2);

4

 web代码测试

    注意web项目中需要添加jstl-1.1.2.jar 和standard-1.1.2.jar
  页面中需要 加入jstl对国际化的支持<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

扫描二维码关注公众号,回复: 674784 查看本文章

然后在需要使用的地方可以使用 :

<fmt:bundle basename="messages">
  <fmt:message key="customer.name">
      <fmt:param value="fwb"></fmt:param>
      <fmt:param value="22"></fmt:param>
  </fmt:message>
 </fmt:bundle>

这样就完成了!

猜你喜欢

转载自fwb7014.iteye.com/blog/1586886