问题描述:当传入的 status值为0 时,不进入 if 判断
<select id="selectAll" parameterType="com.imes.domain.entities.User" resultMap="BaseResultMap">
select * from user
<where>
<if test="status != null and status != ''">
and status = #{status}
</if>
</where>
</select>
执行语句为:
select * from user
原因:
如果是Integer类型的话,如果变量的值是0,即 status = 0, 、
mybatis在进行 status != '' 的时候会认为 status 的值是空字符串, 即 status == '' 为true。
结论:
如果是Integer类型只需要判断 != null 即可