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- ...
随机推荐
- centos7.4上安装python3环境的坑
前言:为了将爬虫项目布置到服务器上,才有了今天这一下午的坑,必须记录 不要动现有的python2环境!不要动现有的python2环境!不要动现有的python2环境! 解压 tar -xvf Pyth ...
- 求值器本质--eval&apply
最近跟着(How to Write a (Lisp) Interpreter (in Python))使用python实现了一个简易的scheme解释器.不得不说使用python这类动态语言实现不要太 ...
- as3.0 橡皮功能2
package com{ import flash.display.MovieClip; import flash.display.Bitmap; import flash.display.Bitma ...
- UVM1
1.UVM: p_sequencer 的使用 http://blog.csdn.net/tingtang13/article/details/46546395
- Devexpress Gridview 自定义汇总CustomSummaryCalculate(加权平均)
Devexpress Gridview 提供了简单的求和,平均等方法,复杂的汇总方法则需要自定义,使用gridview 的CustomSummaryCalculate 事件,根据官网的文档及各论坛案例 ...
- Django之crm
crm注册 crm注册Form from django import forms from crm import models from django.core.exceptions import V ...
- 100-days: The one day
Title:In tech race with China, US universities may lose a vital edge in tech race with 与...的科技比赛中 e ...
- The following packages have unmet dependencies错误
当出现类似这类错误: The following packages have unmet dependencies: python-dev : Depends: python (= 2.7.5-5ub ...
- 【Android端 adb相关】adb相关总结
一.什么是adb? adb的全称是:Android Debug Bridge,adb命令的构成是三部分,分别是:服务器.客户端.后台程序: (1)客户端:一个在PC上运行的客户端.可以通过shell端 ...
- [剑指Offer]42-连续子数组的最大和(DP)
题目链接 https://www.nowcoder.com/practice/459bd355da1549fa8a49e350bf3df484?tpId=13&tqId=11183&t ...