String字符串,添加引号
th:class="${flag=='XXX'} ? 'active' "
boolean类型,注意不能当成字符串处理,不能添加引号
th:style="${session.simpleFlag==false} ? '':'color:red' "
th:if="${session.flg} == #{ERROR}"
数字,注意不能直接使用小于号,会被当成html的元素标签,导致编译出错
th:style="${pageNo}-3>0?'' : 'display: none' "
比较大小
th:style="${sum}-1>${pageNo}?'' : 'display: none' "
判空
th:style="${session.message==null}?'display:none;':'padding:0px 0px 0px 20px;' "
th:unless="${session.flg}==null" 或者 th:unless="${session.flg==null}" 两种方法都行
与运算符应使用转义字符
th:if="${session.dbUser.user.face!=null && session.dbUser.user.face!=''}"
或运算符应直接使用
th:if="${session.dbUser.user.face==null || session.dbUser.user.face==''}"
三目运算符中使用到多个后台数据
th:value="${topic == null} ? 'abc' : ${topic.title}"
th:value="${item.id} == ${section.id} ? 'a' : ${item.b}"
ForEach
<table>
<tr data-th-each="user : ${users}">
<td data-th-text="${user.login}">...</td>
<td data-th-text="${user.name}">...</td>
</tr>
</table>
Switch
<div th:switch="${user.role}">
<p th:case="'admin'">User is an administrator</p>
<p th:case="#{roles.manager}">User is a manager</p>
<p th:case="*">User is some other thing</p>
</div>