简体   繁体   English

MyBatis测试表达式中的AND运算符是否在评估期间短路?

[英]Does the AND operator in MyBatis test expressions short-circuit during evaluation?

Is the AND keyword in test expressions in MyBatis implemented using a short-circuit? MyBatis中的测试表达式中的AND关键字是否使用短路实现? For example, I have written the following: 例如,我写了以下内容:

<when test="pagingInstruction != null
            and pagingInstruction.direction.toString() == 'FORWARD'">
...
</when>

If the first operand resolves to false, will the second operand be ignored? 如果第一个操作数解析为false,第二个操作数是否会被忽略? (I'm using MyBatis v3.0.4.) (我正在使用MyBatis v3.0.4。)

Although it is not stated in the reference doc that the test attribute of the when element short circuits, the reference doc includes an example that only works if the test attribute of the when element short circuits. 虽然在参考文档中没有说明when元素的测试属性短路,但是参考文档包括仅在when元素的测试属性短路时才起作用的示例。

The example is similar to yours; 这个例子与你的相似; here it is: 这里是:

... stuff
<when test="author != null and author.name != null">

The easiest way to resolve your question might be to create some simple unit tests to determine how myBatis treats the "and". 解决问题的最简单方法可能是创建一些简单的单元测试来确定myBatis如何处理“和”。

Also, you may need to test that pageInstruction.direction is not null before calling pageInstruction.direction.toString() . 此外,您可能需要在调用pageInstruction.direction.toString()之前测试pageInstruction.direction不为null。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM