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的更多相关文章

  1. SpringBoot配置属性之Server

    SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之N ...

  2. SpringBoot基础系列-SpringBoot配置

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9990680.html SpringBoot基础系列-SpringBoot配置 概述 属性 ...

  3. springboot上传文件 & 不配置虚拟路径访问服务器图片 & springboot配置日期的格式化方式 & Springboot配置日期转换器

    1.    Springboot上传文件 springboot的文件上传不用配置拦截器,其上传方法与SpringMVC一样 @RequestMapping("/uploadPicture&q ...

  4. springboot配置Druid数据源

    springboot配置druid数据源 Author:SimpleWu springboot整合篇 前言 对于数据访问层,无论是Sql还是NoSql,SpringBoot默认采用整合SpringDa ...

  5. springboot配置详解

    springboot配置详解 Author:SimpleWu properteis文件属性参考大全 springboot默认加载配置 SpringBoot使用两种全局的配置文件,全局配置文件可以对一些 ...

  6. SpringBoot 配置 Servlet、Filter、Listener

    SpringBoot 配置 Servlet.Filter.Listener 在SpringBoot应用中,嵌入式的 Servlet 3.0+ 容器不会直接使用 ServletContainerInit ...

  7. SpringBoot 配置静态资源映射

    SpringBoot 配置静态资源映射 (嵌入式servlet容器)先决知识 request.getSession().getServletContext().getRealPath("/& ...

  8. springboot配置server相关配置&整合模板引擎Freemarker、thymeleaf&thymeleaf基本用法&thymeleaf 获取项目路径 contextPath 与取session中信息

    1.Springboot配置server相关配置(包括默认tomcat的相关配置) 下面的配置也都是模板,需要的时候在application.properties配置即可 ############## ...

  9. springboot配置cxf

    1.引入两个需要的jar <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf- ...

随机推荐

  1. python print 美化

    本来是按照百度搜到的教程来为print输出添加颜色 然后bing了下,已经有封装好的包了,就是python-blessings 效果如图 API网址:https://blessings.readthe ...

  2. 将MYSQL的GBK数据库转成_UTF-8数据库的简便方法

    http://wenku.baidu.com/link?url=epKvsEtUbtzdjQEezGdFMDvJiro3X1yKNgb-1cXzi7CEoYhtoJhImkuyTvVgSmfL6AQL ...

  3. Centos 7 下 Corosync + Pacemaker + psc 实现 httpd 服务高可用

    一.介绍 高可用,大家可能会想到比较简单的Keepalived,或者更早一点的 heartbeat,也可能会用到 Corosync+Pacemaker,那么他们之间有什么区别. Heartbeat到了 ...

  4. NYOJ_矩形嵌套(DAG上的最长路 + 经典dp)

    本题大意:给定多个矩形的长和宽,让你判断最多能有几个矩形可以嵌套在一起,嵌套的条件为长和宽分别都小于另一个矩形的长和宽. 本题思路:其实这道题和之前做过的一道模版题数字三角形很相似,大体思路都一致,这 ...

  5. 203. Remove Linked List Elements (List)

    Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...

  6. java_11接口

    1接口的概念 接口是功能的集合,同样可看做是一种数据类型,是比抽象类更为抽象的”类”. 接口只描述所应该具备的方法,并没有具体实现,具体的实现由接口的实现类(相当于接口的子类)来完成.这样将功能的定义 ...

  7. composer ip2city配置

    //根据ip获取地址信息composer require "mylukin/ip2city: dev-master" // vendor/mylukin/ip2city/src/I ...

  8. vue解决遮罩层滚动方法

    vue 遮罩层阻止默认滚动事件 在写移动端页面的时候,弹出遮罩层后,我们仍然可以滚动页面. vue中提供 @touchmove.prevent 方法可以完美解决这个问题 <div class=& ...

  9. webpack.dev.conf.js

    var utils = require('./utils')var webpack = require('webpack')var config = require('../config') // 一 ...

  10. php5.6 版本出现 Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version 的错误

    解决方法是修改php.ini配置: ;always_populate_raw_post_data = -1 把前面的分号去掉 always_populate_raw_post_data = -1 然后 ...