如何使用百里香检查列表是否为空?

时间:2015-10-13 15:15:47

标签: html html5 thymeleaf

<div th:if="${tblUserList != null}">
 --content--
</div>

上面的百万富翁代码无效,其中tblUserList是一个列表。所以我想检查列表是否为空而不是检查它的null。怎么做?

3 个答案:

答案 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}">