字符串顯示/拼接html
<span th:text="'welcome to our application '+${username}+'!'"></span> <span th:text="|welcome to our application ${username}!|"></span>
if/unless條件spring
<a th:if="${flag == 'yes'}" th:href="@{http://hbk.com}">home</a> <a th:unless="${flag != 'no'}" th:href="@{http://hbk.com}">me</a>
循環app
<tr th:each="user,iterStat:${users}"> <td th:text="${user.name}">hello</td> <td th:text="${iterStat.index}">index</td> </tr>
iterStat爲狀態變量,屬性有:
index 當前迭代對象的index,從0開始
count 當前迭代對象的index,從1開始
size 迭代對象的大小
current 當前迭代變量
even/odd 布爾值,當前循環是不是偶數/奇數,從0開始計算
first 布爾值,當前循環是否第一個
last 布爾值,當前循環是否最後一個less
url的寫法ide
<a th:href="@{http://hbk.com/{type}(type=${type})}">link</a> <a th:href="@{http://hbk.com/{pageId}/can-use-springcloud.html(pageId=${pageId})}">view</a> <div th:style="'background:url('+@{${img url}}+');'">
三目運算符url
<input th:value="${age gt 30 ? '中年' : '年輕'}"/>
gt 大於
ge 大於等於
eq 等於
lt 小於
le 小於等於
ne 不等於spa
switch多條件分支code
<div th:switch="${sex}"> <p th:case="'woman'">女</p> <p th:case="'man'">男</p> <p th:case="*">未知</p> </div>