问题描述
当我在mybatis的mapper查询中使用
<if test="type != null and type != ''">
条件判断时,当type
的类型是数值,并且为0时,type != ''
即type
不为空字符串为false
,这是因为mybatis在将数值与字符串做比较时,0是等于空字符串的,这样显然会出问题,导致在查询时type=0
无法生效。
解决
去掉type != ''
只保留type != null
,因为type是数值类型,所以只需要判断不为null
即可