myBatis自动把0定义为空字符串“”

在开发中,一般在sqlMapper中都会判断参数是否为null,以及是否为空字符串

数据库字段

`stau` int(11) DEFAULT NULL COMMENT '审核状态 0:待审核 1: 打款中 2 打款完成',

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

<if test="status != null and status != ''">中status为integer类型的,status=0的推断结果为false,所以不会执行该sql语句。

当参数为Int类型 0时,myBatis自动把0定义为空字符串“”,开发过程中注意!!!

当status=0时,不会执行该语句,所以去掉and status != ''

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

猜你喜欢

转载自blog.csdn.net/m0_37721946/article/details/79628488
今日推荐