数据库中的字段总会有visible字段来让我们的数据进行软删除,当加入业务流程后,这个visible和业务流程控制中的state(当前业务状态)产生一定的数据冗余,所以我们将visible加入到state中。
但是今天写一个接口时产生了一个问题
dao层的方法
List<CommandCheckListVO> selectByProjectId(@Param("projectId") Long projectId, @Param("state") Integer state);
mapper
<if test="state != null and state != ''">
AND c.state=#{state}
</if>
当Integer为0时,我发现并没有执行语句,有点神奇,于是我增加了一个条件
<if test="state != null and state != '' or state == 0">
AND c.state=#{state}
</if>
添加了 or state == 0 语句后,发现可以正常查询了。
我大概猜想时MyBatis中@Param所对应的属性为Integer时,并且当这个属性的值为0时,那么MyBatis就会把这个属性改为空字符串,导致我的动态SQL那里判断成功。
因此建议大家在设计时还是要去使用0,使用其他的数字来代替0的作用。