select * from sys_user t
<where>
t.is_deleted=0
<if test="u.name != null and u.name != ''">
and t.user_name like concat('%', #{u.name}, '%')
or t.nick_name like concat('%', #{u.name}, '%')
</if>
</where>
之前是这样写的,
数据库查询语句
select * from sys_user t
WHERE
t.is_deleted=0
and (t.user_name like concat('%', '管理员', '%')
or t.nick_name like concat('%', '管理员', '%'))
采用的是or查询,这样直接吧is_deleted=0给过滤掉了。
修改:
<where>
t.is_deleted=0
<if test="u.name != null and u.name != ''">
and (
t.user_name like concat('%', #{u.name}, '%')
or t.nick_name like concat('%', #{u.name}, '%')
)
</if>
</where>