SpringMVC-ResourceBundleMessageSource使用
来源:互联网 发布:狄尼定理知乎 编辑:程序博客网 时间:2024/06/17 02:53
ResourceBundleMessageSource: 提供国际化的类。说的简单点,这个类的作用就是读取资源属性文件(.properties),然后根据.properties文件的名称信息(本地化信息),匹配当前系统的国别语言信息(也可以程序指定),然后获取相应的properties文件的内容。
新建国际化资源文件
i18n_en_US.propertiesmessage=welcome:{0}i18n_zh_CN.propertiesmessage=欢迎:{0}
Bean的配置
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="i18n" /></bean>
使用:
@Test public void test() { ApplicationContext context = new ClassPathXmlApplicationContext("SpringMVC.xml"); System.out.println(context.getMessage("message", new Object[]{"lgh"}, Locale.SIMPLIFIED_CHINESE)); System.out.println(context.getMessage("message", new Object[]{"lgh"}, Locale.US)); }
@Controllerpublic class TestController { @Autowired private ResourceBundleMessageSource messageSource; @RequestMapping(value = "/test4", method = RequestMethod.GET) public String test4(Locale locale) { System.out.println(messageSource.getMessage("message", null, locale)); return "i18n"; }}
ResourceBundleMessageSource 的底层实现依赖于java.util.ResourceBundle
参考:
http://lavasoft.blog.51cto.com/62575/184605/
阅读全文
0 0
- SpringMVC-ResourceBundleMessageSource使用
- Spring 中ResourceBundleMessageSource的使用
- spring中的ResourceBundleMessageSource复习
- spring中的ResourceBundleMessageSource复习
- ResourceBundleMessageSource 和ReloadableResourceBundleMessageSource区别
- spring中的ResourceBundleMessageSource复习
- SpringMVC使用
- SpringMVC使用
- spring中ResourceBundleMessageSource的配置使用方法
- Spring Resource bundle with ResourceBundleMessageSource example
- spring中MessageSource的配置使用方法--ResourceBundleMessageSource
- SpringMVC使用(2)
- springmvc框架的使用
- springmvc使用HttpServletRequest
- springMVC主题的使用
- SpringMVC(2.5)_使用
- SpringMVC中使用AOP
- springmvc标签的使用
- 元素层级
- 2017.11.2笔记
- Hibernate4 基本查询
- bzoj5085 最大
- java基于javamail的验证码邮件发送
- SpringMVC-ResourceBundleMessageSource使用
- 装饰器到底有啥用?
- TOMCAT安装环境变量配置
- 洛谷 P3938 斐波那契
- 设计模式学习总结:装饰者模式(Decorator Pattern)
- POST和GET
- python web自动化
- RHCSA测试题
- Ajax提交表单时kindeditor编辑器中的内容如何赋值给textarea