使用“logic:equal”和“logic:equal”有什么区别?和“逻辑:不等于”标签?
例如,我可以有这样的代码:
<logic:equal name="userForm" property="isRishi" value="YES">
Welcome, your name is Rishi</logic:equal>
和另一个这样的代码:
<logic:notEqual name="userForm" property="isRishi" value="NO">
Welcome, your name is Rishi</logic:notEqual>
两者的功能相同。那么使用这两个标签有什么区别呢?
For example, I can have a code like:
<logic:equal name="userForm" property="isRishi" value="YES">
Welcome, your name is Rishi</logic:equal>
And another code like this:
<logic:notEqual name="userForm" property="isRishi" value="NO">
Welcome, your name is Rishi</logic:notEqual>
Both would function the same. So what difference is there in using these two tags?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果只有两个可能的值,唯一的区别是第二种形式由于双重否定而更难理解。
如果
isRishi
可以有“YES”和“NO”以外的值(例如null),那么差异应该是明显的。If there are only two possible values, the only difference is that the second form is harder to understand due to the double negation.
If
isRishi
can have values other than "YES" and "NO" (e.g. null) then the difference should be obvious.它们的存在是为了更好的可读性。
notEqual to no
很复杂,更难理解。而且,出于同样的原因
!
运算符存在。They exist for better readability.
notEqual to no
is convoluted and harder to grasp.And also, for the same reason why the
!
operator exists.还有其他情况。如果您想在“是”的情况下做一件事,而在非“是”的情况下做另一件事怎么办?您可以将另一种情况表述为等于“否”,但是(a)它可能为空,并且(b)如果您没有布尔值,但有其他值,则可能有许多您不感兴趣的值。
There is also the else-case. What if you want to do one thing in the "YES" case and one in the not-YES case? You could phrase the other case as equal to NO, but (a) it might be null and (b) if you dont have boolean but something else there might be many values you are not interested in.