天天看点

MyBatis模糊查询like语句

第1种:在Java代码中添加sql通配符。

string wildcardname = “%smi%”;
    list<name> names = mapper.selectlike(wildcardname);
 
    <select id=”selectlike”>
     select * from foo where bar like #{value}
    </select>
           

第2种:在sql语句中拼接通配符,会引起sql注入:

string wildcardname = “smi”;
    list<name> names = mapper.selectlike(wildcardname);
 
    <select id=”selectlike”>
         select * from foo where bar like "%"#{value}"%"
    </select>
           

继续阅读