问题
I have the following:
@Data
public class SomeClass {
List<SomeBean> beans = new ArrayList();
}
If I have a List
of SomeClass
beans, is there an easy way to check whether the beans
list is empty?
For example, something like this doesn't work (logically): th:if="${#lists.isEmpty(someClass?.beans)}"
Perhaps a utility that can flatten the lists?
I could instead put this on the server-side, but didn't know whether there was an easy way to do it on the front-end.
回答1:
For these kinds of things, look at collection selection and collection projection. In your case an expression like this should work:
th:if="${#aggregates.sum(listOfSomeClass.![beans.size()]) == 0}"
来源:https://stackoverflow.com/questions/63623608/how-to-check-isempty-on-a-list-of-lists-in-thymeleaf