文章目录
在mybatis中,一般模糊查询like习惯用concat进行拼接,但是当传入的参数为空时,查询不出数据。
那是因为concat中,若传入参数为null, 则返回null。

以下整理mybatis中like模糊查询的写法
<select id="findByKeyword" resultMap="BaseResultMap">
select * from user
<where>
1=1
<if test="keyword!=null and keyword!=''">
AND user_name like CONCAT('%',#{keyword},'%')
</if>
</where>
</select>
因为keyword可能为null, 所以先在外层对keyword参数进行判空处理。
或者通过ifnull函数对参数进行一下判断,若传入参数为null,则转换为空字符串
<select id="findByKeyword" resultMap="BaseResultMap">
select * from user
where user_name like CONCAT('%',ifnull(#{keyword},''),'%')
</select>


![算法刷题[比较两个字符串的最大公字符串(滑动窗口实现)]](https://i-blog.csdnimg.cn/direct/6af95068bd694ce2903eaac48ad24f71.png)




![[机器学习]聚类算法](https://i-blog.csdnimg.cn/direct/c6bd87d6624549b2ae42242560f4ebbe.png)











