有时候我们在使用Mybatis时,常常会判断属性是否为空
<if test="plan_id != null and plan != ''">
and plan_id = #{plan_id}
</if>
当plan_id为Integer类型,并且plan_id值为0时,该if判断却为false。
当plan_id为0时,Mybatis会解析成'' 空字符串。
为了避免这个问题,改成下面这样写,去掉对空字符的判断,就解决了该问题
<if test="plan_id!= null">
and plan_id= #{plan_id}
</if>