mybatis动态查询Integer类型入参为0不生效的问题

白玉神驹 / 2023-08-17 / 原文

解决

//Integer类型入参,动态sql判断只需要判null即可
<if test="status != null "> and status = #{status}</if>

原因

mybatis源码在预编译sql时,使用OGNL表达式来解析if标签,对于Integer类型属性,(status != '')会当作(status!=0)来判断