在做mubatis-plus的模糊查询
问题:
项目报错

查询得知
mybatis 各种数据库模糊查询的写法
// An highlighted block
--all 用$不能防sql注入
select * from user where name like '%${name}%'
--mysql,oracle (db2的concat函数只支持2个参数)
select * from user where name like concat('%',#{name},'%')
--oracle,db2
select * from user where name like '%'||#{name}||'%'
--SQL Server
select * from user where name like '%'+#{name}+'%'
--据说这种是预编译,有空测下
select * from user where name like "%"#{name}"%"
尝试性把代码从
中的@Select(" select * from domain where id like’%#{id}%’ ")
更改为
这个 @Select(" select * from domain where id like’%${id}%’ ")
结论
mybatis-plus中模糊查询中数据值用${}表示
本文探讨了在MyBatis Plus中实现模糊查询的方法,并详细对比了几种不同数据库的SQL写法,指出了使用字符串拼接的方式存在的安全隐患及推荐使用的解决方案。
747

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



