In this short Q&A article, we are going to present how to check if the list is empty in Thymeleaf. This is a common task and many developers face this problem when processing collections in templates.
The solution is pretty simple. Fortunately, Thymeleaf comes with special utility class for lists that has several helper methods.
To check if list is empty use
#lists.isEmpty(list) utility method.
Use the following snippet to check if list is empty:
In case you need to check if list is NOT EMPTY use:
If you not familiar with
th:unless statement please check list of available condition statements in thymeleaf.