Spring中的国际化的处理
2014-03-22 11:56
393 查看
在applicationContext.xml文件或是其他名字的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" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd"> <!-- 配置国际化的操作,这是固定的方式 --> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames"> <list> <!-- 设置读取的配置文件message.properties --> <value>message</value> </list> </property> </bean> </beans> 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);
相关文章推荐
- java框架之spring(国际化处理)
- idea在处理spring国际化解决中文乱码,properties的格式:native-to-ascii
- spring-boot使用AOP统一处理日志
- Spring+hibernate+mysql事物不回滚的原因以及处理
- Spring 系列,第 4 部分: Spring JMS 消息处理 1-2-3
- springmvc/springboot处理前台字符串日期自动转换成后台date类型的三种办法
- spring ApplicationContext生成和获取国际化信息的方法
- Spring-国际化信息01-基础知识
- Spring对注解(Annotation)处理源码分析2——解析和注入注解配置的资源
- SpringBoot 多任务并行+线程池处理的实现
- Spring MVC Controller与jquery ajax请求处理json
- springCloud(12):使用Hystrix实现微服务的容错处理-Hystrix的监控
- Spring的事务处理之声明式事务处理
- Struts1的国际化处理(汇总整理)
- 第十七章 Spring 事件处理(Spring Framework3.1教程)
- Hibernate 事务处理和spring中配置事务
- SpringBoot非官方教程 | 第二十篇: 处理表单提交
- spring事件处理
- Angular开发(二十一)-关于国际化的处理
- Springboot(统一异常处理)