<select id="selectStudentLikeName1" resultType="stu">
select * from t_student where name like '%' #{xxx} '%'
</select>
<!-- 使用数据库提供的字符串拼接函数实现模糊查询
注意:不是所有数据库中的都提供concat函数
不推荐
-->
<select id="selectStudentLikeName2" resultType="stu">
select * from t_student where name like concat('%',#{name},'%')
</select>
<!--
$ 是字符串拼接
使用字符拼接实现模糊查询,没使用预编译,因此执行效率低、安全性低
使用语法如果参数对象为基本数据格式那么只能填写value 如果是实体类则填写属性名
不推荐
-->
<select id="selectStudentLikeName3" resultType="stu">
select * from t_student where name like '%${value}%'
</select>
MyBatis模糊查询的3种查询方式
最新推荐文章于 2022-07-31 19:26:49 发布
本文探讨了在MyBatis中实现模糊查询的多种方法,包括使用百分号通配符、数据库提供的字符串拼接函数以及预编译方式,对比了各种方法的执行效率和安全性,旨在帮助开发者选择最适合的模糊查询策略。
979

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



