一、if判断
1、注意事项:
(1)test比较字符串:如test="customerType == 'abc' "会发现判断无效,报错Error querying database. Cause: java.lang.NumberFormatException:。解决方法:
方法一:<when test='customerType == "abc"'> 用单引号包住最外层,里面使用 双引号引用是可以的。外单内双;
方法二:<when test="customerType == 'abc'.toString()"> 在引用字符串参数后 加上 toString() 方法,mybatis在反射的时候会加上方法。
(2)test比较number类型的0:在<if test="param!= ''" >中,如果param 是number类型,而且值为0,会有 0==''情况发生(mybatis 源码中String类型的"",在判断中通过对String的长度判断进行赋值,而""在判断逻辑中等同于0.0D,结果为double dv2=0.0),解决方法:
1)参数类型改为String类型;
2)不用<if test="param!= ''" >,只用<if test="param!= null " >,参数做判断,如果为'' 则赋值 null
二、if..else ...if
<choose>
<when test="params!=null">
right JOIN
</when>
<otherwise>
LEFT JOIN
</otherwise>
</choose>
三、where
只有在一个

最低0.47元/天 解锁文章
720

被折叠的 条评论
为什么被折叠?



