thymeleaf 国际化
Spring Boot 设计网站,考虑到国际化,一般采用Thymeleaf,因为thymeleaf对spring boot 的支持更好,在学习的过程中,走了很多弯路,网上教程涉及到Spring Boot的国际化教程比较少,所以,写下学习过程。
目的:在google浏览器中,更改语言设置,会出现相应的界面,如下图
英文显示
中文显示
开发环境: STS(Spring Boot Tool Suite )
原理:1)引进thymeleaf包
2)在template中HTML文件上引用thymeleaf
3)在java/main/resource 中创建语言文件,只设计了中文和英文的,如图:
4)在标签中,使用#{}引用,具体用法参考官方网站:
http://www.thymeleaf.org/
5)引用后,如果正常的话,在google修改语言,会出现相应的语言界面。
在创建好相应语言的.properties文件后,在项目运行后,会自动的的加载Messageresource bean,然后,thymeleaf就可以直接使用了.properties的数据了,很简单的。
showName.html的代码 ,为了方便,我只给出最上面的那个访问模态的代码。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
<meta charset="UTF-8"/>
<meta content="text/html"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<link th:href="@{bootstrap/css/bootstrap.min.css}" rel="stylesheet"/><title>Insert title here</title>
</head>
<body><div class="panel panel-primary"><div class="panel-heading"><h3 class="panel-title" th:utext="#{System.title}">visit model</h3></div>
</body>
</html>
messages_zh_CN代码
System.title=\u8BBF\u95EE\u6A21\u6001
System.list=\u5217\u8868
System.getName=\u83B7\u53D6\u59D3\u540Dinfo.name=\u59D3\u540D
info.age=\u5E74\u9F84
messages_en_US代码
System.title=visit model
System.list=list
System.getName=getName#getName
info.name=name
info.age=age
运行程序,当然,在spring_boot 中,直接运行html是不提倡的,需要controller来指引,具体的不细说。
在国际话的过程中,出现点问题!国际化过程中,由于版本问题出现的错误!
thymeleaf 国际化相关推荐
- 一篇文章解决springboot+thymeleaf多语言国际化
1.前言 博主最近在写一个多语言的项目,因为之前没实际接触过多语言的设计,所以写这篇文章记录下这次多语言开发的过程. 博主的开发环境是:Springboot1.5.6 + thymeleaf,需要注意 ...
- 自己动手在Spring-Boot上加强国际化功能
前言 公司将项目由Struts2转到Springmvc了,由于公司业务是境外服务,所以对国际化功能需求很高.Struts2自带的国际化功能相对Springmvc来说更加完善,不过spring很大的特性 ...
- 【Thymeleaf】格式化日期
前言 thymeleaf 3.0 spring boot 2.0.0RELEASE 无国际化:格式化日期 <p>Today is: <span th:text="${#ca ...
- 玩转springboot2.x之搭建Thymeleaf官方示例程序
1 thymeleaf 官方示例程序介绍 前面我已经介绍了如何在spirngboot2.0中使用freemarker和jsp,今天我们来说一下如何在springboot2.0中如何使用Thymelea ...
- 4-Spring Boot 的视图
Spring Boot可整合的模板引擎技术 1. FreeMarker 2. Groovy 3. Thymeleaf 4. Mustache -- Thymeleaf 基本语法 Thymeleaf是一 ...
- 15 | SpringBoot + thymeleaf 的登陆页面如何实现国际化
1.编写国际化配置文件,抽取页面需要显示的国际化消息 (1)在resources文件夹下创建i18n文件夹,用来存放国际化配置文件,为什么是i18n??? i18n(其来源是英文单词 internat ...
- springboot+thymeleaf或者springboot+freemarker的国际化
springboot+thymeleaf 参考网站http://blog.csdn.net/lwphk/article/details/41822447 pom.xml <dependency& ...
- Thymeleaf - 使用方法及国际化(超详细)
Thymeleaf简介 Thymeleaf是一个和Velocity.FreeMarker 类似的模板引擎,它在有网络和无网络的环境下皆可运行.因为它支持html原型,在html的标签里增加了额外的属性 ...
- [JAVAEE] Thymeleaf 基本语法:常用表达式
Thymeleaf 基本语法 常用表达式 变量表达式 ${ } 使用方法:th:xx = "${ }" 获取对象属性值给 th:xx . 后台代码: Student s=new S ...
最新文章
- linux之LAMP架构优化
- pool python 传参数_Python-爬虫-多线程、线程池模拟(urllib、requests、UserAgent、超时等)...
- WebAssembly增加Go语言绑定
- Python-100 | 练习题 01 列表推导式
- 我要带徒弟学JAVA架构 ( 写架构,非用架构 )
- Android 系统(55)---Android App开发之ANR异常的原因分析及处理总结
- jquery请求后台数据(get请求)
- MySQL/InnoDB中,乐观锁、悲观锁、共享锁、排它锁、行锁、表锁、死锁概念的理解...
- iOS TableView性能优化
- Axure8.0激活码
- 原创|批处理实现MicroUSB传输速度测试工具
- GPS NMEA码详解
- MGRE ISP是路由器(思科设备)
- 恶意程序检测之malconv模型
- 【开源代码】-基于国民N32G45x系列MCU使用JLINK的RTT Viewer/logger/Client组件工具
- JVM年轻代和老年代垃圾回收
- 苹果邮箱怎么登录qq邮箱_怎么登陆邮箱?公司mail邮箱在哪登录?
- 一位开发大神的“告别信”!
- TLV自定义通信协议的编码和解析
- Arista发布容器化、开放EOS版本