Mybatis模糊搜索like用法

Mybatis模糊搜索有4种方法:

第一种:

select * from user where name like #{name};

传入参数前先拼接“%”,如要想模糊查询“红”,传入参数时传入“%红%”

第二种:

select * from user where name like '%${name}%';

这种情况下,传入参数时直接传入“红”,使用了$容易导致SQL注入,不建议使用

第三种:

select * from user where name like concat('%',#{name},'%');

直接传入参数“红”即可,不会引起SQL注入

第四种:

select * from user where name like "%"#{name}"%";

直接传入参数“红”即可

猜你喜欢

转载自blog.csdn.net/qq_42500503/article/details/108876822