mybatis ~查询时传入参数为0被误认为是空字符串

今天在mbatis中使用Xml配置sql语句时,出现了这样一个问题。当我传入的参数为0去做判断时,mybatis会把参数0当成是空字符串去判断而引起查询结果错误。

解决方式1:

当传入的参数有0时,只判断!=null即可。

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

解决方式2:

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

解决方式3:

将0转化为String类型,就可以解决这个问题。

猜你喜欢

转载自blog.csdn.net/zf18234031156/article/details/89399297
今日推荐