mybatis test把整数0等同于空字符串

今天在使用mybatis时遇到一个问题,java代码中传递的整数0在mybatis中被识别成null

 

   <where>
   	<if test="status != null and status !=''">
   		and status=#{status,jdbcType=INTEGER}
   	</if>
   </where>

 

 

如果java代码需要往mybatis传递整数0,那么需要使用增强版的判断,具体如下所示:

 

   <where>
   	<if test="status != null and status !='' or status=='0'.toString()">
   		and status=#{status,jdbcType=INTEGER}
   	</if>
   </where>

或者可以采用

   <where>
   	<if test="@org.apache.commons.lang3.StringUtils@isNotEmpty(status)">
   		and status=#{status,jdbcType=INTEGER}
   	</if>
   </where>

 

第二种方式是采用了自定义的判断逻辑,第一种方式则是采用ognl的判断逻辑!!!

 

具体原因可以参考:https://blog.csdn.net/john1337/article/details/98225453

 

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值