How to check if list is empty using thymeleaf?
<div th:if="${tblUserList != null}">
--content--
</div>
The above thymeleaf code is not working, where tblUserList is a list. So I want to check whether the list is empty instead of checking its null. How to do that?
You can do as follows:
<div th:if="${not #lists.isEmpty(tblUserList)}">
--content--
</div>
With Thymeleaf 3.x.x you can validate list more elegant:
<div th:if="${tblUserList!=null and !tblUserList.empty}"></div>
or
<div th:if="${tblUserList!=null and !tblUserList.isEmpty()}"></div>
Or simply:
<div th:if="${!myList.empty}">