Re: Characters in IF statement

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Characters in IF statement

Patrick Bond
I just ran into this issue myself, I know this was posted 10 years ago but it still apparently is an issue so I hope this helps anyone else that comes across this thread. 

You can't use == because its not comparing strings correctly, so your immediate thought should be to use the following (note this will may still NOT work)

<if test="irregularity.equals('B')">

</if>

The above will only work if the variable "irregularity" was defined as a char. If it is defined as a string, this will still not work. This is caused by the Single quotes around the 'B', which in the xml will read as a character and the conditional will then be comparing a string to a character and will not yield a correct result (although it doesn't throw an error).

Instead, you need to flip the quotes around, single quotes on the outside and double quotes on the inside. This will compare a string and string.

<if test = 'irregularity.equals("B")'>

</if>

Now as long as irregularity is a string you should yield a correct result.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...