srping boot thymeleaf 学习总结 (2) - thymeleaf properties 国际化 mesaage
thymeleaf获取配置properties中的数据与thymeleaf国际化(摘录)
使用thymeleaf提供的国际化
有时候会有直接在模板中获取配置文件properties中的配置信息,比如:webname = form1,不需要用java传给模板,在模板中就可以直接获取的方法
首先我们先定义国际化资源文件,spring boot默认就支持国际化的,而且不需要你过多的做什么配置,
只需要在resources/下定义国际化配置文件即可,注意名称必须中messages开始,要不然识别不了,
因为springboot默认将国际化的配置文名称定义为messages,当然你也可以改变这个默认的配置
我们定义如下几个文件:
messages.properties (默认,当找不到语言的配置的时候,使用该文件进行展示)。
messages_zh_CN.properties(中文)
messages_en_US.properties(英文)
具体的代码如下:
messages.properties:
welcome = 欢迎你登录form1.cn网站(
default
)
messages_zh_CN.properties:
welcome = \u6b22\u8fce\u4f60\u767b\u5f55\u5230 \u963f\u91cc\u5df4\u5df4 \u7f51\u7ad9\uff08\u4e2d\u6587\uff09 #unicode
messages_en_US.properties:
welcome = welcome to login to form.cn website(English)
修改hello.html文件,使用#{key}的方式进行使用messages中的字段信息:
<!DOCTYPE html>
<html>
<head>
<meta charset=
"UTF-8"
/>
<title>hello spring boot</title>
</head>
<body>
<p><label th:text=
"#{welcome}"
></label></p>
</body>
</html>
重新访问:http://127.0.0.1:8080/hello 应该显示:
欢迎你登录到form1.cn网站(中文)
如果网站没有多语言的需求,那么就做一个 messages.properties 来放自己的一些配置
注:如果你的messages.properties中文乱码,那么 对工程进行 settings 找到 File Encodings 然后改为utf-8即可
srping boot thymeleaf 学习总结 (2) - thymeleaf properties 国际化 mesaage的更多相关文章
- Spring Boot 学习笔记--整合Thymeleaf
1.新建Spring Boot项目 添加spring-boot-starter-thymeleaf依赖 <dependency> <groupId>org.springfram ...
- Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客
==他的博客应该不错,没有细看 Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客 http://blog.csdn.net/u012706811/article/det ...
- Spring Boot学习记录(二)–thymeleaf模板
自从来公司后都没用过jsp当界面渲染了,因为前后端分离不是很好,反而模板引擎用的比较多,thymeleaf最大的优势后缀为html,就是只需要浏览器就可以展现页面了,还有就是thymeleaf可以很好 ...
- spring boot ----> 常用模板freemarker和thymeleaf
===========================freemarker=================================== freemarker 官网:https://freem ...
- Spring Boot—06集成前端模板thymeleaf
Spring Boot建议使用这些模板引擎,避免使用JSP,若一定要使用JSP将无法实现Spring Boot的多种特性 pom.xml <dependency> <groupId& ...
- springboot学习日志(二)-- thymeleaf学习
本次学习如何使用thymeleaf以及相关语法1.在上一章写的那样 引入jar包到maven工程 <dependency> <groupId>org.springframewo ...
- Thymeleaf学习记录(1)--启动模板及建立Demo
Thymeleaf是什么? Thymeleaf是适用于Web和独立环境的现代服务器端Java模板引擎.相比于JSP,Thymeleaf更简洁,渲染性能更好,维护性更好,它可以XML/XHTML/HTM ...
- Thymeleaf 学习笔记
(一)Thymeleaf 是个什么? 简单说, Thymeleaf 是一个跟 Velocity.FreeMarker 类似的模板引擎,它可以完全替代 JSP .相较与其他的模板引擎,它有如下三个极吸引 ...
- thymeleaf 学习笔记-基础篇(中文教程)
(一)Thymeleaf 是个什么? 简单说, Thymeleaf 是一个跟 Velocity.FreeMarker 类似的模板引擎,它可以完全替代 JSP .相较与其他的模板引擎,它有如下 ...
随机推荐
- An internal error occurred during: "Android Library Update".
打开 proj.android下的.cproject文件,把多余的CConfiguration配置节删掉,只留第一个就行了.
- redis的maxmemory与maxmemory-policy关系
如果redis配置了maxmemory和maxmemory-policy策略,则当redis内存数据达到maxmemory时,会根据maxmemory-policy配置来淘汰内存数据,以避免OOM.r ...
- 什么是HBASE(三) HBase的压缩和编码
在存储层面节省空间的处理上,Hbase提供了两种方案,一个是基于key的编码,一个是基于数据块(data block)的压缩.前者用于将key重复部分进行简单处理达到节约空间的目的,后者则是对数据块进 ...
- Web service 框架比较CXF xfire aisx2 aisx
Web 服务框架.它还体现了从 Axis 1.x 系列获得的经验和最近两年在 Web 服务领域的发展.推出 Axis2 的主要原因之一是从速度和内存方面获得更好的性能——不过还添加了一些新特性和功能. ...
- SpringCloud初体验:前言
体验了一天 SpringCloud 后发现,人们所讲的微服务架构不是一门技术,而是一种风格. 感觉确实可以这么认同,因为一套 SpringCloud 玩下来(未深入.未完整「链路追踪.动态刷新配置…… ...
- Python download a image (or a file)
http://stackoverflow.com/questions/13137817/how-to-download-image-using-requests import shutil impor ...
- phalcon安装笔记
参考官网 git clone --depth= git://github.com/phalcon/cphalcon.git cd cphalcon/build sudo ./install 添加配置文 ...
- Devexpres下窗体带阴影的边框效果
public partial class Form1 : DevExpress.XtraEditors.XtraForm { public Form1() { InitializeComponent( ...
- 10-28质量监控ELK
监控业务范围 app崩溃监控(Bugly) 应用性能监控(APM) 业务监控(TalkingData.友盟) 质量监控(缺位) 质量监控平台ELK elk官网 数据构造 线上错误状态分布 故障影响范围 ...
- UE4关于Oculus Rift (VR)开发忠告
转自:http://blog.csdn.net/cartzhang/article/details/42493843 UE4虚拟现实 实现的注意事项 https://docs.unrealengine ...