<div th:if="${tblUserList != null}">
--content--
</div>
上面的百万富翁代码无效,其中tblUserList是一个列表。所以我想检查列表是否为空而不是检查它的null。怎么做?
答案 0 :(得分:83)
您可以执行以下操作:
<div th:if="${not #lists.isEmpty(tblUserList)}">
--content--
</div>
答案 1 :(得分:35)
使用 Thymeleaf 3.x.x ,您可以更优雅地验证列表:
<div th:if="${tblUserList!=null and !tblUserList.empty}"></div>
或
<div th:if="${tblUserList!=null and !tblUserList.isEmpty()}"></div>
答案 2 :(得分:3)
或者简单地:
<div th:if="${myList.empty}">