当前位置: 代码迷 >> 综合 >> Mybatis模糊搜索like用法
  详细解决方案

Mybatis模糊搜索like用法

热度:51   发布时间:2024-02-24 01:19:52.0

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}"%";

直接传入参数“红”即可

 

  相关解决方案