如何检查 EL 中的布尔条件? [英] How to check a boolean condition in EL?
本文介绍了如何检查 EL 中的布尔条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是正确的吗?
<c:if test="${theBooleanVariable == false}">It's false!</c:if>
或者我可以这样做吗?
<c:if test="${!theBooleanVariable}">It's false!</c:if>
推荐答案
可以看一下EL(表达式语言)描述此处.
You can have a look at the EL (expression language) description here.
你的两个代码都是正确的,但我更喜欢第二个,因为将布尔值与 true
或 false
进行比较是多余的.
Both your code are correct, but I prefer the second one, as comparing a boolean to true
or false
is redundant.
为了更好的可读性,您还可以使用 not
运算符:
For better readibility, you can also use the not
operator:
<c:if test="${not theBooleanVariable}">It's false!</c:if>
这篇关于如何检查 EL 中的布尔条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文