做查询遇到一个坑,想用字符串去判断是否等于一个数字字符串"1",没报错但匹配不上,写法如下
<if test="taskIdType != null and taskIdType != '0' ">
and task_id like CONCAT(CONCAT('TASK', #{taskIdType}), '%')
</if>
正确写法如下:
1.数字字符串后面用toString()方法
<if test="taskIdType != null and taskIdType != '0'.toString() ">
and task_id like CONCAT(CONCAT('TASK', #{taskIdType}), '%')
</if>
2.外层用单引号' ',内层用双引号" "
<if test='taskIdType != null and taskIdType != "0" '>
and task_id like CONCAT(CONCAT('TASK', #{taskIdType}), '%')
</if>
如果入参是数字类型的条件也不生效taskIdType=1下面这个条件也不生效
<if test="taskIdType != null and taskIdType != '' ">
and task_id like CONCAT(CONCAT('TASK', #{taskIdType}), '%')
</if>