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 )