问题描述
我有以下几点:
@Data
public class SomeClass {
List<SomeBean> beans = new ArrayList();
}
如果我有一个 SomeClass
bean 的 List
,是否有一种简单的方法来检查 beans
列表是否为空?
If I have a List
of SomeClass
beans, is there an easy way to check whether the beans
list is empty?
例如,这样的事情(逻辑上)不起作用:th:if="${#lists.isEmpty(someClass?.beans)}"
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.
推荐答案
对于这类事情,看 集合选择 和 集合投影.在您的情况下,这样的表达式应该有效:
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}"
这篇关于如何在 Thymeleaf 中的列表列表中检查 isEmpty?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!