有时候我们在写sql的时候,没办法像在mybaties文件中那样用if进行判断。想如下这种:
<if test='savePoint != null and savePoint != ""'>
and smtrls.save_point = #{savePoint,jdbcType= VARCHAR}
</if>
<if test='currentHandler != null and currentHandler != "" '>
and smtrls.pick_user = #{currentHandler,jdbcType= VARCHAR}
</if>
但是也需要传参数,有时候参数如果为空,也要能查到数据。
但是如果直接!=‘’会查询不到数据。
如下查不到数据
SELECT t.*, t.rowid from fnd_user t WHERE t.id != ''
等价于
SELECT t.*, t.rowid from fnd_user t WHERE t.id IS NULL
这种情况可以这样处理:
参数为空的时候,因为有or 连接,or条件成立,就能查到数据。
餐位不为空的时候,就会过滤参数结果,or条件不成立。
SELECT t.*, t.rowid from fnd_user t WHERE (t.id != #{params} OR #{params} IS NULL)