Spring 中的国际化

<? xml version = " 1.0 "  encoding = " UTF-8 " ?>
< beans
    xmlns
= " http://www.springframework.org/schema/beans "
    xmlns:xsi
= " http://www.w3.org/2001/XMLSchema-instance "
    xsi:schemaLocation
= " http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd " >



< bean id = " messageSource "   class = " org.springframework.context.support.ResourceBundleMessageSource " >
< property name = " basename "  value = " messages " ></ property >

 
</ bean >

</ beans >
import  java.util.Date;
import  java.util.Locale;

import  org.springframework.context.ApplicationContext;
import  org.springframework.context.MessageSource;
import  org.springframework.context.support.ClassPathXmlApplicationContext;

public   class  TestBean  {
    
    
public static void main(String[] args) {
        
        ApplicationContext context
=null;
        
        context
=new ClassPathXmlApplicationContext("guojihua.xml");
        Object[] a
=new Object[]{"郑成桥",new Date()};
    System.out.println(context.getMessage(
"user", a,Locale.SIMPLIFIED_CHINESE));
        
    }

}


上面Object[] 里面的user 是国际化里的配置的
user=\u6B22\u8FCE{0},\u7684\u5230\u6765\u73B0\u5728\u662F{1}

如果看不懂 ,  就直接加我的 QQ 问吧...


你可能感兴趣的:(Spring 中的国际化)