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- ...
随机推荐
- Python基础之列表及元组的增删改查
定义一个列表 晚上的状态不太适合写博客,容易犯困~ 列表的增加有三种方式 第一种主流的增加 append函数 list1 = ['noevil', 'fordearme', 'city', 'cust ...
- 【C++】STL算法之remove_if
之前写过这样一段代码: auto iter=remove_if(AllEdges.begin(),AllEdges.end(),[&](Edge* edge){return _isEedge( ...
- 【Nodejs】Expressのファイルアップロード(FileUpload)のMulterについて
https://github.com/expressjs/multer/blob/master/doc/README-zh-cn.md Multer 是一个 node.js 中间件,用于处理 mult ...
- rancher2 HA部署注意事项
参考: https://rancher.com/docs/rancher/v2.x/en/installation/ha-server-install/ https://www.cnblogs.com ...
- HDU-1069.MonkeyandBanana(LIS)
本题大意:给出n个长方体,每种长方体不限量,让你求出如何摆放长方体使得最后得到的总高最大,摆设要求为,底层的长严格大于下层的长,底层的宽严格大于下层的宽. 本题思路:一开始没有啥思路...首先应该想到 ...
- ASP.Net MVC 在ajax接收controller返回值为Json数据
首先,再次回忆一下ajax的标准用法:(这张图写的比较详细了)(转) 页面部分ajax代码: $.ajax({ url: "/Home/Login?account=&q ...
- cloud配置中心遇到的坑
https://blog.csdn.net/z960339491/article/details/80593982分布式配置中心为什么要有用分布式配置中心这玩意儿?现在这微服务大军已经覆盖了各种大小型 ...
- GridView和DataFormatString 日期格式 精确小数点后位数
如果DataFormatString无效,请添加属性 HtmlEncode = "false" --------------------------------------- Da ...
- web中CookieUtils的工具类
该类中包含Web开发中对Cookie的常用操作,如需要Copy带走 package com.project.utils; import java.io.UnsupportedEncodingExcep ...
- Ubuntu防火墙配置
转载自:http://blog.csdn.net/sumer0922/article/details/7485584Ubuntu11.04默认的是UFW(ufw 即uncomplicated fire ...