springboot国际化配置
来源:互联网 发布:软件测试职位有哪些 编辑:程序博客网 时间:2024/06/11 01:46
messages_zh_cn.properties中文配置文件
messages_en.properties英文配置文件
messages.properties默认配置文件
对于中文的属性文件,我们编写好后,应该使用jdk提供的native2ascii命令把文件转换为unicode编码的文件。命令的使用方式如下:
native2ascii 源文件.properties 目标文件.properties (有时间报:java.lang.Exception: 无法读取messages.)1.对下文件名保持正确;2.换到E盘或D盘根目录,cmd到根目录执行就好了
为了防止出现中文乱码:用utf-8对messages.properties进行转码,转码后保存到messages_zh_cn.properties文件
native2ascii -encoding UTF-8 messages.properties messages_zh_cn.properties
建立取message方法
* Created by 飞尘 on 2017/3/20. */@Configurationpublic class InternationalConfig { @Value(value = "${spring.messages.basename}") private String basename; @Bean(name = "messageSource") public ResourceBundleMessageSource getMessageResource() { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setBasename(basename); return messageSource; }}
/** * Created by 飞尘 on 2017/3/20. */@Componentpublic class MessageUtil { @Autowired private MessageSource messageSource; /** * 根据code取message * @param code 值 * @return */ public String getMessage(String code) { return this.getMessage(code,null); } /** * 根据code取message * @param code 值 * @param param 参数 * @return */ public String getMessage(String code, String[] param) { return messageSource.getMessage(code, param, LocaleContextHolder.getLocale()); }}
reset.greeting=Dear {0} {1}可以传多参数,具体还要自己多试验
0 0
- springboot国际化配置
- springboot配置国际化
- SpringBoot validator国际化随笔
- Springboot国际化i18n
- springboot+freemarker国际化
- SpringBoot与Thymeleaf实现国际化
- springboot配置
- springboot配置
- SpringBoot配置
- 【SpringBoot】SpringBoot核心-基本配置
- 【SpringBoot】SpringBoot核心-外部配置
- SpringBoot-01SpringBoot配置FastJson
- velocity国际化配置
- JSP国际化配置
- Spring MVC国际化配置
- Spring MVC国际化配置
- Spring国际化配置
- Struts2 配置国际化支持
- Activity嵌套多个fragment时,onResume的处理
- L2-012. 关于堆的判断
- js 工具类方法
- HDU:1142 A Walk Through the Forest
- 跳转到指定的viewpager页面
- springboot国际化配置
- Android Studio 2.3 instant run与miui冲突问题的解决
- docker基本命令
- websocket需要tomcat8.5.8以上版本才支持
- java基础----1
- golang简单的抓取
- 菜鸟教程链接
- iOS Line drawing tool(画线类, 直线和 折线)
- Windows pip不是内部命令