mybatis 的like多条件使用
当使用like需要模糊查询多条件的时候,而且有可能只查询一个条件,所以有条件会为null,建议使用下面这种方法:
SELECT
cu.id,
cu.nick_name AS nickName,
cu.phone,
cuaa.assets
FROM client_user cu
left join client_user_account cuaa on cu.id = cuaa.client_user_id
where 1 = 1
<if test="nickName != null">
and cu.nick_name like "%"#{nickName}"%"
</if>
<if test="phone != null">
AND cu.phone like "%"#{phone}"%"
</if>
本文介绍在MyBatis中如何实现模糊多条件查询,特别是在条件可能为null的情况下,通过使用<if>标签来动态构建SQL语句,确保查询的灵活性和准确性。
1898

被折叠的 条评论
为什么被折叠?



