mybatis if test 表达式

mybatis中有这样一个SQL判断,

<if test="status != null and status !='' ">

and a.STATUS = #{status,jdbcType=SMALLINT}

</if>

status是一个Byte类型对象,当status = 1时判断成立,status=0 就不成立,按理说都应该成立的。自己试着把status !=’’ 去掉之后就都成立了。后来网上查了好久,才明白mybatis会把number类型的0当成false,非0为true,类似于JavaScript中0!=''结果为false,从而导致=0的时候判断总是不成立。
其实只有String类型才需要判断!='',number类型根本不需要。

 

mybatis if test 不为空字符串或null

<if test="type !=null and type !=''">
AND l.type=#{type,jdbcType=INTEGER}
</if>

mybatis if test 字符串比较 是否等于 abc(使用双引号)

<if test="type !=null and type ==&quot;abc&quot;  ">

</if>

mybatis if test 字符串比较 是否等于 a(使用单引号)

<if test="type !=null and type =='a'  ">

</if>

 

mybatis if test 字符串比较 是否等于 abc(使用toString)

<if test="type !=null and type ==‘abc’.toString()  ">

</if>

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值