Html 如何使用百里香叶检查列表是否为空?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33106391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 18:21:29 来源:igfitidea点击:
How to check if list is empty using thymeleaf?
提问by Rahul Raj
<div th:if="${tblUserList != null}">
--content--
</div>
The above thymeleaf code is not working, where tblUserList is a list. So I want to check whether the list is empty instead of checking its null. How to do that?
上面的 thymeleaf 代码不起作用,其中 tblUserList 是一个列表。所以我想检查列表是否为空而不是检查它的空值。怎么做?
回答by taxicala
You can do as follows:
您可以执行以下操作:
<div th:if="${not #lists.isEmpty(tblUserList)}">
--content--
</div>
回答by Alexey Nikitenko
With Thymeleaf 3.x.xyou can validate list more elegant:
使用Thymeleaf 3.xx,您可以更优雅地验证列表:
<div th:if="${tblUserList!=null and !tblUserList.empty}"></div>
or
或者
<div th:if="${tblUserList!=null and !tblUserList.isEmpty()}"></div>
回答by Zon
Or simply:
或者干脆:
<div th:if="${myList.empty}">