MyBatis 参数Integer类型 值为0时被解析为空字符串

来源:互联网 发布:招聘网络推销员 编辑:程序博客网 时间:2024/06/05 20:22

在用MyBatis进行对数据库的操作时,经常会写到类似下面的if判断

<if test="type != null and type != ''">    and type = #{type} </if>

但发现上面例子中,type为Integer类型的参数,当type的值为0时,该if判断却为false。

后经调试发现,当type值为0时,Mybatis将0解析为了空字符串‘’。为了避免这个问题,改成下面这样写,去掉对空字符的判断,就解决了该问题

<if test="type != null">    and type = #{type} </if>

但是还是不知道为什么会这样,求告知。


0 0