使用mybatis时遇到了一个bug,磨了一个下午,最后查看别人的文章最后总算解决了,这里记录下。
原文章在这里:https://blog.youkuaiyun.com/weixin_43244841/article/details/107339953
为了防止该url失效,我先大致的记下该bug如何发生和解决的。
在写代码中,遇到了需要在sql中判断传入的参数是什么数据。
<if test="status!=null and status != ''">
and status = #{status}
</if>
但是当status传入参数为Integer类型且值为0时,那个就会出现问题了。该判断进不去。
解决方案:
<if test="status!=null and status != '' or 0==status">
and status = #{status}
</if>
或者
<if test="status!=null ">
and status = #{status}
</if>