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>
3 个解决方案
#1
105
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或false进行比较是多余的。
For better readibility, you can also use the not
operator:
为了更好的可读性,您还可以使用not运算符:
<c:if test="${not theBooleanVariable}">It's false!</c:if>
#2
19
Both works. Instead of ==
you can write eq
两者都有效。而不是==你可以写eq
#3
2
You can check this way too
你也可以这样检查
<c:if test="${theBooleanVariable ne true}">It's false!</c:if>
#1
105
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或false进行比较是多余的。
For better readibility, you can also use the not
operator:
为了更好的可读性,您还可以使用not运算符:
<c:if test="${not theBooleanVariable}">It's false!</c:if>
#2
19
Both works. Instead of ==
you can write eq
两者都有效。而不是==你可以写eq
#3
2
You can check this way too
你也可以这样检查
<c:if test="${theBooleanVariable ne true}">It's false!</c:if>