Spring国际化实例
来源:互联网 发布:cf手游机枪数据 编辑:程序博客网 时间:2024/06/13 00:25
MainDemo.java
package org.eimhe;
import java.util.Date;
import java.util.Locale;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class MainDemo {
public static void main(String[] args) {
ApplicationContext context=null;
context=new FileSystemXmlApplicationContext("org/eimhe/applicationContext.xml");
UserBean user=(UserBean)context.getBean("user");
System.out.println("username="+user.getUsername());
System.out.println("age="+user.getAge());
Object[] objs=new Object[]{"syb",new Date().toString()};
//www.eimhe.com为资源文件的key值,objs为资源文件value值所需要的参数,Local.CHINA为国际化为什么语言
String str=context.getMessage("www.eimhe.com", objs, Locale.CHINA);
System.out.println(str);
}
}
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="user" class="org.eimhe.UserBean" abstract="false"
singleton="true" lazy-init="default" autowire="default"
dependency-check="default" destroy-method="clear">
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource"
abstract="false" singleton="true" lazy-init="default"
autowire="default" dependency-check="default">
<property name="basenames">
<list>
<value>eimhe</value>
</list>
</property>
</bean></beans>
eimhe_en_US.properties
www.eimhe.com=welcome {0},time:{1}
eimhe_zh_CN.properties
www.eimhe.com=欢迎 {0},时间:{1}
UserBean.javapackage org.eimhe;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.DisposableBean;
public class UserBean implements InitializingBean,DisposableBean{
private String username;
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public void init(){
this.username="zhangsan";
this.age=20;
}
public void clear(){
this.username="";
this.age=0;
}
public void afterPropertiesSet() throws Exception {
this.username="wangwu";
this.age=20;
}
public void destroy() throws Exception {
this.username="";
this.age=0;
}
}
- Spring国际化实例
- 解决spring国际化不能实例化bean的问题
- Spring国际化
- spring国际化
- spring 国际化
- spring 国际化
- spring国际化
- spring 国际化
- spring国际化
- spring 国际化
- spring 国际化
- Spring 国际化
- spring国际化
- spring国际化
- Spring 国际化
- spring国际化
- spring 国际化
- Spring国际化
- 使用struts的同步令牌避免form的重复提交
- Struts令牌防止重复提交
- Token令牌防重复提交实例
- [ApplicationEvent][ApplicationListener]
- Spring国际化时报NoSuchMessageException
- Spring国际化实例
- Struts文件上传实例
- 关于SQL2008日志文件处理
- PropertyEditorSupport注入值实例
- tar系列解压缩相关
- Spring AOP实例
- Spring AOP 实例2
- Tiles框架使用
- 马云为何在赌城拉斯维加斯逢赌必赢