提问者:小点点

如何使用胸腔检查列表是否为空?


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

上面的thymelaf代码不起作用,其中tblUserList是一个列表。所以我想检查列表是否为空,而不是检查其空值。如何做到这一点?


共3个答案

匿名用户

您可以执行以下操作:

<div th:if="${not #lists.isEmpty(tblUserList)}">
 --content--
</div>

匿名用户

使用Thymelaf 3.x.x,您可以更优雅地验证列表:

<div th:if="${tblUserList!=null and !tblUserList.empty}"></div>

<div th:if="${tblUserList!=null and !tblUserList.isEmpty()}"></div>

匿名用户

或者简单地说:

<div th:if="${!myList.empty}">