【发布时间】:2011-04-24 08:42:39
【问题描述】:
这对吗?
<c:if test="${theBooleanVariable == false}">It's false!</c:if>
或者我可以这样做吗?
<c:if test="${!theBooleanVariable}">It's false!</c:if>
【问题讨论】:
这对吗?
<c:if test="${theBooleanVariable == false}">It's false!</c:if>
或者我可以这样做吗?
<c:if test="${!theBooleanVariable}">It's false!</c:if>
【问题讨论】:
两者都有效。你可以写eq而不是==
【讨论】:
你可以看看EL(表达式语言)描述here。
您的两个代码都是正确的,但我更喜欢第二个,因为将布尔值与 true 或 false 进行比较是多余的。
为了更好的可读性,您还可以使用not 运算符:
<c:if test="${not theBooleanVariable}">It's false!</c:if>
【讨论】:
你也可以这样检查
<c:if test="${theBooleanVariable ne true}">It's false!</c:if>
【讨论】: