Java 评估列表是否为空 JSTL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1463597/
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-12 12:33:09  来源:igfitidea点击:

Evaluate if list is empty JSTL

javajspjstl

提问by OscarRyz

I've been trying to evaluate if this array list is empty or not but none of these have even compiled:

我一直在尝试评估这个数组列表是否为空,但这些都没有编译:

<c:if test="${myObject.featuresList.size == 0 }">                   
<c:if test="${myObject.featuresList.length == 0 }">                 
<c:if test="${myObject.featuresList.size() == 0 }">                 
<c:if test="${myObject.featuresList.length() == 0 }">                   
<c:if test="${myObject.featuresList.empty}">                    
<c:if test="${myObject.featuresList.empty()}">                  
<c:if test="${myObject.featuresList.isEmpty}">  

How can I evaluate if an ArrayList is empty?

如何评估 ArrayList 是否为空?

采纳答案by bobince

emptyis an operator:

empty是一个运算符

The emptyoperator is a prefixoperation that can be used to determine whether a value is null or empty.

所述empty操作者是一个前缀,可以被用来确定一个值是否为空值或空白操作。

<c:if test="${empty myObject.featuresList}">

回答by Steve B.

There's also the function tags, a bit more flexible:

还有功能标签,更灵活一点:

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<c:if test="${fn:length(list) > 0}">

And here'sthe tag documentation.

这里的标签文档。