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- ...
随机推荐
- oracle存储过程与存储函数的区别和联系
相同点:1.创建语法结构相似,都可以携带多个传入参数和传出参数. 2.都是一次编译,多次执行. 不同点:1.存储过程定义关键字用procedure,函数定义用function. 2.存储过程 ...
- Codeforces Beta Round #16 (Div. 2 Only)
Codeforces Beta Round #16 (Div. 2 Only) http://codeforces.com/contest/16 A 水题 #include<bits/stdc+ ...
- Git下基本命令操作
提前准备好一个文件夹,并且进入该文件夹. 1.clone Github 上的Repository,如: git clone git@github.com:Git账号用户名/项目名称.git 2.仓库初 ...
- Sobel Derivatives
https://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/sobel_derivatives/sobel_derivatives.html ...
- Comparing Code Playgrounds Codepen, JSFiddle, JS Bin, Dabblet, CSS Deck, and Liveweave
What is a code playground? Codepen, JSFiddle, JS Bin, Dabblet, CSS Deck, and Liveweave are HTML, CSS ...
- mysql联表更新使用join
update TableA as a inner join TableB as b on a.order_id=b.order_id set a.last_time='2018-01-01' whe ...
- python 面向对象编程 之 单例模式
单例模式三种实现方式: 单例模式:单例模式是解决系统资源浪费的一种方案,是指一个类实例化后可以多次使用此对象. 单例模式应用场景:数据库操作.日志.后台打印 # settings.py# Host=' ...
- spingmvc项目根路径访问不到
问题: 如何改mvc中项目的欢迎页,或者叫做根路径 一个东西快弄完了,就剩下一个问题,应该是个小问题.就是mvc项目的欢迎页,怎么给改下呢 访问根路径http://localhost/demo 怎么都 ...
- C# 一个数组未赋值引发的错误
在电脑前又是一天,后来脑子也糊里糊涂,可能是基础还不牢固,设置断点,找了找问题才发现数组定义出了问题, 我是这样定义数组的,string[] auths ; string auths=new stri ...
- Oracle_PL/SQL(6) 触发器(序列、视图)
序列1.创建序列create sequence seq_alog start with 1 increment by 1 maxvalue 999999999999999999999999999 mi ...