如何在 Thymeleaf 中的列表列表中检查 isEmpty? [英] How to check isEmpty on a List of Lists in Thymeleaf?

查看:52
本文介绍了如何在 Thymeleaf 中的列表列表中检查 isEmpty?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下几点:

@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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆