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? For example, I have written the following:
<whe开发者_运维问答n test="pagingInstruction != null
and pagingInstruction.direction.toString() == 'FORWARD'">
...
</when>
If the first operand resolves to false, will the second operand be ignored? (I'm using 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.
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".
Also, you may need to test that pageInstruction.direction
is not null before calling pageInstruction.direction.toString()
.
精彩评论