#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
,下列表达式都求值为true
boolean
值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
。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)