天天看點

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>
           

繼續閱讀