Spring中的国际化的处理

2014-11-24 00:41:56 · 作者: · 浏览: 0
在applicationContext.xml文件或是其他名字的spring配置文件中进行设置,

基本的配置如下:

  

  

	
   
	
    
     
      
      
message
message.properties国际化配置文件的书写: ##其中{num}是占位符,从0开始记录 hello=welcom,{0}-{1}-{2}-{3}-{4}-{5}-{6}-{7}-{8}-{9}-{10}-{11} now=new is\:{0} 测试类中的调用: // 加载配置文件 ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "applicationContext.xml"); // 国际化 // 查找到message.properties中的key为hello的进行返回,如果有占位符就采用数组的方式进行赋值 String hello = applicationContext.getMessage("hello", new Object[] {"spring", "1", "2", "3", "4", "5", "6", "7", "ba", "九", "十", "十一" }, Locale.getDefault()); System.out.println(hello);