Mybatis的if test字符串比较问题(报NumberFormatException异常)

No.1

<if test="isFlag=='Y'">
and msg.expire_time &lt; now()
</if>
会报NumberFormatException异常,这样就可以了。
<if test="isFlag=='Y'.toString()">
and msg.expire_time &lt; now()
</if>

No.2

<if test=" name=='hellworld' ">

<if>

这样会有问题,换成

<if test=' name=="hellworld" '>

<if>

原因:mybatis是用OGNL表达式来解析的,在OGNL的表达式中,单引号里单个字符会被解析成char类型(多个字符是可以的),java是强类型的,char 和一个string 会导致不等

猜你喜欢

转载自blog.csdn.net/weixin_45818787/article/details/122956702