字符串显示/拼接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>