Java 如何检查 EL 中的布尔条件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3915716/
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
How to check a boolean condition in EL?
提问by wiki
Is this correct?
这样对吗?
<c:if test="${theBooleanVariable == false}">It's false!</c:if>
Or could I do this?
或者我可以这样做吗?
<c:if test="${!theBooleanVariable}">It's false!</c:if>
采纳答案by Romain Linsolas
You can have a look at the EL (expression language) description here.
您可以在此处查看 EL(表达式语言)描述。
Both your code are correct, but I prefer the second one, as comparing a boolean to true
or false
is redundant.
您的两个代码都是正确的,但我更喜欢第二个,因为将布尔值与true
or进行比较false
是多余的。
For better readibility, you can also use the not
operator:
为了更好的可读性,您还可以使用not
运算符:
<c:if test="${not theBooleanVariable}">It's false!</c:if>
回答by kiritsuku
Both works. Instead of ==
you can write eq
两者都有效。而不是==
你可以写eq
回答by Shams
You can check this way too
您也可以通过这种方式检查
<c:if test="${theBooleanVariable ne true}">It's false!</c:if>