标签:
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(); }
标签:
原文地址:http://www.cnblogs.com/Nyan-Workflow-FC/p/4778991.html