当查问条件有Boolean类型的时候,为false时查问有效
<if test="isOk != null and isOk !=''"> and is_ok = #{isOk}</if>
- 当isOk = false 时,并未查问出is_ok对应的后果来
-- sql: 没有拼接where = isOk的条件select * from tableName;
- 当 isOk = true 时,查问后果正确
-- sqlselect * from tableName where is_ok = true ;
问题所在:
<if test="isOk != null and isOk !=''">
正确写法
- Boolean类型默认值为null,只须要判断是否为null
<if test="isOk != null"> and is_ok = #{isOk}</if>
- isOk = '' , 会将 '' 转换成null解决