mybatis 参数为Integer型数据并赋值0时,0被当作空处理,解决及缘由

mybatis 参数为Integer型数据并赋值0时,0被当作空处理:html

mybatis.xml中有if判断条件判断参数不为空时,赋值为0的Integer参数被mybatis判断为空, 不执行<if test="param != null and param != ''"></if>的sql。sql

解决方法: 判断非空改成:<if test="param != null"</if>apache

用到mybatis时,避免用0来作值mybatis

官方解释: https://commons.apache.org/proper/commons-ognl/language-guide.htmlide

Interpreting Objects as Booleans Any object can be used where a boolean is required. OGNL interprets objects as booleans like this: If the object is a Boolean, its value is extracted and returned; If the object is a Number, its double-precision floating-point value is compared with zero; non-zero is treated as true, zero as false; If the object is a Character, its boolean value is true if and only if its char value is non-zero; Otherwise, its boolean value is true if and only if it is non-null.ui

相关文章
相关标签/搜索