万隆的笔记 万隆的笔记
博文索引
笔试面试
  • 在线学站

    • 菜鸟教程 (opens new window)
    • 入门教程 (opens new window)
    • Coursera (opens new window)
  • 在线文档

    • w3school (opens new window)
    • Bootstrap (opens new window)
    • Vue (opens new window)
    • 阿里开发者藏经阁 (opens new window)
  • 在线工具

    • tool 工具集 (opens new window)
    • bejson 工具集 (opens new window)
    • 文档转换 (opens new window)
  • 更多在线资源
  • Changlog
  • Aboutme
GitHub (opens new window)
博文索引
笔试面试
  • 在线学站

    • 菜鸟教程 (opens new window)
    • 入门教程 (opens new window)
    • Coursera (opens new window)
  • 在线文档

    • w3school (opens new window)
    • Bootstrap (opens new window)
    • Vue (opens new window)
    • 阿里开发者藏经阁 (opens new window)
  • 在线工具

    • tool 工具集 (opens new window)
    • bejson 工具集 (opens new window)
    • 文档转换 (opens new window)
  • 更多在线资源
  • Changlog
  • Aboutme
GitHub (opens new window)
  • Spring

  • SprinvMVC

  • SpringBoot

    • Spring Boot 简介
    • Hello Spring Boot
    • Spring Boot 常用配置
    • YAML 配置文件语言
    • 为什么说 JSON 不适合做配置文件?
    • Spring Boot 整合 Thymeleaf
    • Thymeleaf 常用语法
    • Thymeleaf 表达式语法
      • Message 表达式
      • 变量表达式
      • 选择变量表达式
      • 链接 URL 表达式
      • 变量
      • 算数运算
      • 真假运算
      • 比较运算
      • 条件运算
    • Thymeleaf 内置对象
    • Spring Boot 整合 Druid
    • Spring Boot 整合 HikariCP
    • Spring Boot 整合 tk.mybatis & PageHelper
    • MyBatis 生成代码 Maven插件
    • Spring Boot 配置拦截器
  • Spring
  • SpringBoot
2021-08-02
目录

Thymeleaf 表达式语法

# Thymeleaf 表达式语法

# Message 表达式

#{...}


<p th:utext="#{home.welcome(${session.user.name})}"> Welcome to our grocery store, Sebastian Pepper!</p>
<p th:utext="#{${welcomeMsgKey}(${session.user.name})}"> Welcome to our grocery store, Sebastian Pepper!</p>

# 变量表达式

${}

ongl 标准语法,方法也可以被调用

# 选择变量表达式

*{}

<div th:object="${session.user}">
    <p>Name: <span th:text="*{firstName}">Sebastian</span>.</p>
    <p>Surname: <span th:text="*{lastName}">Pepper</span>.</p> 
    <p>Nationality: <span th:text={nationality}">Saturn</span>.</p>
</div> 

等价于

<div>
    <p>Name: <span th:text="${session.user.firstName}">Sebastian</span>.</p> 
    <p>Surname: <span th:text="${session.user.lastName}">Pepper</span>.</p> 
    <p>Nationality: <span th:text="${session.user.nationality}">Saturn</span>.</p>
</div>

当然了,这两者可以混合使用
还有一种方式

<div>
    <p>Name: <span th:text="*{session.user.name}">Sebastian</span>.</p> 
    <p>Surname: <span th:text="*{session.user.surname}">Pepper</span>.</p> 
    <p>Nationality: <span th:text="*{session.user.nationality}">Saturn</span>.</p>
</div>  

# 链接 URL 表达式

@{}

<!-- Will produce 'http://localhost:8080/gtvg/order/details?orderId=3' (plus rewriting) --> <a href="details.html"

th:href="@{http://localhost:8080/gtvg/order/details(orderId=${o.id})}">view</a> <!-- Will produce '/gtvg/order/details?orderId=3' (plus rewriting) -->

<a href="details.html" th:href="@{/order/details(orderId=${o.id})}">view</a>

<!-- Will produce '/gtvg/order/3/details' (plus rewriting) -->

<a href="details.html" th:href="@{/order/{orderId}/details(orderId=${o.id})}">view</a>

# 变量

分类 实例
文本 one text,Another one!,...
数字 0 , 34 , 3.0 , 12.3 ,…
真假 true , false
文字符号 one , sometext , main ,…

# 算数运算

分类 实例
+, -, *, /, % 二元运算符
- 减号(一元运算符)

# 真假运算

分类 实例
and , or 二元运算符
! , not 否定(一元运算符)

# 比较运算

分类 实例
>, <, >=, <= (gt, lt, ge, le) 比较
== , != ( eq , ne ) 平等

# 条件运算

分类 实例
if-then (if) ? (then)
if-then-else (if) ? (then) : (else)
Default (value) ?: (defaultvalue)
上次更新: 5/30/2023, 12:51:40 AM
Thymeleaf 内置对象

Thymeleaf 内置对象→

最近更新
01
2025
01-15
02
Elasticsearch面试题
07-17
03
Elasticsearch进阶
07-16
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式