Thymeleaf消息表达式
来源:互联网 发布:王者荣耀淘宝充值 编辑:程序博客网 时间:2024/09/21 08:16
消息表达式用于从消息源中提取消息内容实现国际化。
表达式的语法:#{...}
<p th:utext="#{home.welcome}">Welcome to our grocery store!</p>
消息属性可以是传统的静态值
home.welcome=¡Bienvenido a nuestra tienda de comestibles!
也可以带有参数声明,参数声明格式符合java.text.MessageFormat标准
home.welcome=¡Bienvenido a nuestra tienda de comestibles, {0}!
通过在消息名称后边加括号声明参数的方式#{messageKey(param=value)}
实现参数赋值
<p th:utext="#{home.welcome(${session.user.name})}"> Welcome to our grocery store, Sebastian Pepper!</p>
多个参数用“,”
分割
#{messageKey(param1=value1, param2=value2)}
messageKey本身可以是一个变量表达式
<p th:utext="#{${welcomeMsgKey}(${session.user.name})}"> Welcome to our grocery store, Sebastian Pepper!</p>
消息源
大多数情况下, 消息源是.properties文件,同时可以自定义其他消息源,比如数据库。消息源通过org.thymeleaf.messageresolver.IMessageResolver获取,如果在初始化模板引擎时没有自定义的IMessageResolver被提供,那么一个默认的实现org.thymeleaf.messageresolver.StandardMessageResolver会被自动提供。
StandardMessageResolver查找和模板文件位于同级目录,且具有和模板文件相同名字的.properties文件。
模板/WEB-INF/templates/home.html在渲染时,会根据local设置,使用下面的消息源文件
- /WEB-INF/templates/home_zh_CN.properties for中文
- /WEB-INF/templates/home_en.properties for英文
- /WEB-INF/templates/home.properties 如果特定的lcoal不可用时使用
0 0
- Thymeleaf消息表达式
- Thymeleaf系列二 简单表达式: 变量、消息、Literals、文本、算术、比较和条件表达式
- thymeleaf条件表达式
- Thymeleaf模板表达式
- Thymeleaf变量表达式
- Thymeleaf选择变量表达式
- Thymeleaf URL表达式
- Thymeleaf 标准表达式语法
- Thymeleaf标准表达式语法
- thymeleaf 基本表达式
- Thymeleaf条件表达式和默认表达式
- Thymeleaf的表达式语言-原标题:Expression Language in Thymeleaf
- Thymeleaf教程 (四) Thymeleaf标准表达式语法(上)
- Thymeleaf教程 (五) Thymeleaf标准表达式语法(下)
- Thymeleaf教程 (四) Thymeleaf标准表达式语法(上)
- Thymeleaf教程 (五) Thymeleaf标准表达式语法(下)
- using thymeleaf之二简单表达式
- using thymeleaf之五条件表达式
- 常见斐波那契数列的性质及其应用
- AndroidStudio中由于代码问题造成的Selector无效问题
- 【编程】--C语言
- 菜鸟学linux 当查看某个命令功能时,出现1,2,3...的数字代表的是什么意思
- 17年寒假阅读页面索引
- Thymeleaf消息表达式
- 2017.2.11【初中部 GDKOI】模拟赛B组
- STL中的全排列next_permutation函数
- 寒假篇33
- Android Studio 怎么创建setter/getter、Override Methods
- TreeMap简析
- Samba实现ubuntu与window文件共享
- 保研尹始
- 错误“Unexpected namespace prefix "xmlns" found for tag LinearLayout”的解决方法