mybatis中if比较字符串相等时报错或者无效

当在mybatis的if标签中比较字符串时,需要特别注意,如果字符串长度为1,不能写成如下形式,不然会报错.

注:空代表长度为0,也不会报错



为了避免错误,可以写成如下形式(外面单引号里面双引号 或者 使用对象的toString() 或者使用对象的equals()方法 )

注:mybatis可以直接调用对象的方法,包含自定义方法

<if test='isReCreate=="1"'>
    and i.unusualType in ("0","2")
</if>
<if test="isCombine=='w'.toString()">
    and i.invoiceStatus not in ("5","7")
</if>
<if test="isCombine.equals('1')">
    and i.invoiceStatus not in ("5","7")
</if>

猜你喜欢

转载自blog.csdn.net/qq_33315102/article/details/80608394