springboot配置il8n
springMvc下,配置i18n:
1.配置ResourceBundleMessageSource管理国际化资源文件
2.在页面使用fmt标签取出国际化内容
springBoot下,自动配置了i18n:
1.新建目录,存放login_zh_CN.properties (基础名_zh_CN.properties)对应中文编码
login_en_US.properties对应英文
login.properties对应默认
idea会自动转成resource bundle层级,可以打开相关界面(底部中间),设置k-v

2.配置spring.messages.basename
springBoot默认配置basename为messages,读取根目录下的messages.properties
这里设置spring.messages.basename = il8n.login
3.页面集成thymeleaf,使用#{login.btn},获取国际化的内容
4.制定自己的LocaleResolver //Locale为区域信息对象
自动配置的LocaleResolver默认读取请求头中的的地区信息,来切换国际化内容
现在想通过点击 中文/Enlish 按钮来切换,并且默认读取请求头来切换:
//通过按钮绑定url地址,追加参数L=zh_CN 或者L=en_US来实现
public class MyLocaleResolver implements LocaleResolver {
@Override
public Locale resolveLocale(HttpServletRequest request) {
String l = request.getParameter("L");
Locale locale = Locale.getDefault();//使用默认配置
if(!StringUtils.isEmpty(l)){
String[] split = l.split("_");
locale = new Locale(split[],split[]);// new Locale(语言,国家)
}
return locale;
}
@Override
public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale
locale) {
}
}
@Bean
public LocaleResolver localeResolver(){
return new MyLocaleResolver();
}
}
springboot配置il8n的更多相关文章
- SpringBoot配置属性之Server
SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之N ...
- SpringBoot基础系列-SpringBoot配置
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9990680.html SpringBoot基础系列-SpringBoot配置 概述 属性 ...
- springboot上传文件 & 不配置虚拟路径访问服务器图片 & springboot配置日期的格式化方式 & Springboot配置日期转换器
1. Springboot上传文件 springboot的文件上传不用配置拦截器,其上传方法与SpringMVC一样 @RequestMapping("/uploadPicture&q ...
- springboot配置Druid数据源
springboot配置druid数据源 Author:SimpleWu springboot整合篇 前言 对于数据访问层,无论是Sql还是NoSql,SpringBoot默认采用整合SpringDa ...
- springboot配置详解
springboot配置详解 Author:SimpleWu properteis文件属性参考大全 springboot默认加载配置 SpringBoot使用两种全局的配置文件,全局配置文件可以对一些 ...
- SpringBoot 配置 Servlet、Filter、Listener
SpringBoot 配置 Servlet.Filter.Listener 在SpringBoot应用中,嵌入式的 Servlet 3.0+ 容器不会直接使用 ServletContainerInit ...
- SpringBoot 配置静态资源映射
SpringBoot 配置静态资源映射 (嵌入式servlet容器)先决知识 request.getSession().getServletContext().getRealPath("/& ...
- springboot配置server相关配置&整合模板引擎Freemarker、thymeleaf&thymeleaf基本用法&thymeleaf 获取项目路径 contextPath 与取session中信息
1.Springboot配置server相关配置(包括默认tomcat的相关配置) 下面的配置也都是模板,需要的时候在application.properties配置即可 ############## ...
- springboot配置cxf
1.引入两个需要的jar <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf- ...
随机推荐
- mongodb-参考其他
MongoDB教程 http://www.runoob.com/mongodb/mongodb-window-install.html
- 如何正确获取MYSQL的ADO连接字符串
首先你正确安装了MYSQL的数据库驱动程序(mysql-connector-odbc-5.3.2-win32.msi )http://dev.mysql.com/downloads/connector ...
- pycharm的安装(图文)
pycharm的安装, PyCharm是一种 IDE,可以在里面对python代码调试.语法高亮.Project管理.跳转.智能提示.自动完成.单元测试.版本控制.pycharm提供了一些高级功能,以 ...
- cisco 交换机通过console 导入 IOS
准备说明: 电脑上安装有 SecureCRT 软件 导入 IOS: 第一步:使用 SecureCRT 连接上交换机.进入rommon 模式(Ctrl+Break组合键) 第二部:设置波特率为11520 ...
- 【转】自动化测试框架: pytest&allure ,提高自动化健壮性和稳定性
序 在之前,我写过一个系列“从零开始搭建一个简单的ui自动化测试框架(pytest+selenium+allure)”,在这个系列里,主要介绍了如何从零开始去搭建一个可用的自动化工程框架,但是还缺乏了 ...
- 201. Bitwise AND of Numbers Range (Bit)
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND(按位与) of all nu ...
- 取得<asp:TextBox中的值:
取得<asp:TextBox中的值: var a= document.getElementById("<%= (ID名).ClientID %>").valu ...
- 100-days: Three
Title: Singapore(新加坡) set to raise retirement ages as seniors stay healthier be set to do sth. 准备做某 ...
- Python: 定时器(Timer)简单实现
项目分析中发现有网站下载过程中需要发送心跳指令,复习下定时器,其与javascript中实现方法类似. 其原理为执行函数中置定时函数Timer(),递归调用自己,看来实现方法比较拙劣. 假定1秒触发一 ...
- JDK1.5 Excutor 与ThreadFactory
Excutor 源码解读: /** * An object that executes submitted {@link Runnable} tasks. This * interface provi ...