user2504767
user2504767

Reputation:

How to combine complex boolean expression by using MyBatis?

I have the following MyBatis code snippet, but the SQL code won´t be executed in my complete SQL statement (the boolean variable has the right values):

<when test="deletedParticipation == true and canceledParticipation == true and openedParticipation == false">
     AND     ( myTable.myColumn1 IS NOT NULL OR myTable.myColumn2 = 1 )                     
</when>

I think it is more clearly, if I doesn´t show you the complete SQL statement. Is that the right way to combine more than two boolean variables to an complex boolean expression? Working with parenthesis doesn´t working too.

Upvotes: 0

Views: 7561

Answers (2)

Lavish Kothari
Lavish Kothari

Reputation: 2331

You can use the following:

<if test="deletedParticipation.booleanValue() and canceledParticipation.booleanValue() and !openedParticipation.booleanValue()">

Note that you can always use java-methods (that are public) on the objects. So you can also do something like

<if test="someCollection != null and someCollection.size() > 0">

Upvotes: 1

Florian Schaetz
Florian Schaetz

Reputation: 10662

The answer is suprisingly simple:

test="deletedParticipation and canceledParticipation and openedParticipation"

...works fine, no need to compare them to true, since they are already boolean expressions... If one of the three parameters is false or null, the test will be false, so no need to check for null either.

Upvotes: 1

Related Questions