码迷,mamicode.com
首页 > 编程语言 > 详细

spring international

时间:2015-09-02 17:20:40      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

1.beans.xml setting

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basenames">
            <list>
            <!-- 其中一个资源文件,如放在com.nyan包则写com.nyan.message -->
          <value>message</value>         </list> </property> </bean>

@src建立properties资源文件

hello,now是键名

value 的值跟properties的文件对应:<value>notice</value> --- >notice_en_US.properties>

hello=welcome,{0}
now=now is,{0}

@命名格式:message_语言_国家

message_en_US.properties

message_zh_CN.properties

@applicationContext.getMessage("键名","参数","区域")

   public void messageTest(){
        ClassPathXmlApplicationContext context = new  ClassPathXmlApplicationContext("bean.xml");
        String [] a= {"读者"};
        String hello = context.getMessage("hello", a, Locale.getDefault());
        System.out.println("default.....");
        Object [] b ={ new Date()};
        String now = context.getMessage("now", b, Locale.getDefault());
        
        hello = context.getMessage("hello", a, Locale.US);
        now = context.getMessage("now", b, Locale.US);
        
        hello = context.getMessage("hello", a, Locale.CHINESE);
        now = context.getMessage("now", b, Locale.CHINESE);
        
        context.close();
    }

 

spring international

标签:

原文地址:http://www.cnblogs.com/Nyan-Workflow-FC/p/4778991.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!