#th:if
th:if属性求Bool值,只有true的时候其所在的标签及该标签中的内容才会被渲染到输出结果中
<a href="comments.html" th:href="@{/product/comments(prodId=${prod.id})}" th:if="${not #lists.isEmpty(prod.comments)}">view</a>th:if=“expression”对expression求值有下述规则
值不为null,下列表达式都求值为trueboolean值true本身非0数非'0'字符"false", "off", "no"之外的字符串boolean,number,character,string之外的任意其他对象值为null被认为是false#th:unless
th:unless是th:if的一个相反操作,上面的例子可以改写为
<a href="comments.html" th:href="@{/comments(prodId=${prod.id})}" th:unless="${#lists.isEmpty(prod.comments)}">view</a>#th:switch/th:case
<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>一旦某个case求值为true,剩余的case则都当做false,“*”指明默认case。