How to check isEmpty on a List of Lists in Thymeleaf?

岁酱吖の 提交于 2021-02-11 12:55:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!