SpringBoot教程
SpringBoot入门案例
SpringBoot框架Web开发
SpringBoot非web应用程序
SpringBoot使用拦截器
SpringBoot中使用Servlet
SpringBoot中使用Filter
SpringBoot项目配置字符编码
SpringBoot打包与部署
SpringBoot使用Actuator
SpringBoot集成Thymeleaf模板
SpringBoot总结及综合案例
SpringBoot工程下使用Mybatis反向工程

Thymeleaf字面量、字符串拼接及运算符

Thymeleaf字面量

字面量:对应数据类型的合法取值,可以在html页面直接使用,不需要后台传递。

1.文本字面量

用单引号'...'包围的字符串为文本字面量

!--文本字面量-->
<a th:href="@{'/user/' + ${user.id}}">修改用户</a>

2.数字字面量


<!--数字字面量-->
<p>今年是<span th:text="2017">1949</span>年</p>
<p>20年后, 将是<span th:text="2017 + 20">1969</span>年</p>

3.boolean字面量

true和false


<!--boolean字面量-->
<p th:if="${sex == true}">执行操作</p>

4.null字面量

<!--null字面量-->
<p th:if="${user == null}">user为空</p>
<p th:if="${user != null}">user不为空</p>

Thymeleaf字符串拼接

<!--一种是字面量使用加号拼接-->
<span th:text="'当前是第'+${sex}+'页 ,共'+${sex}+'页'"></span>

<!--另一种更优雅的方式,使用“|”减少了字符串的拼接的加号-->
<span th:text="|当前是第${sex}页,共${sex}页|"></span>

Thymeleaf运算符

三元运算:

<span th:text="${sex == 1?'男':'女'}"></span>
<span th:text="${sex eq 1?'男':'女'}"></span>

算术运算:+ , - , * , / , %

关系比较: > , < , >= , <= ( gt , lt , ge , le )

相等判断:== , != ( eq , ne )

全部教程