模糊查询like语句该怎么写?
第1种:在Java代码中添加sql通配符。
html// 这里是java代码 string wildcardname = "%smi%"; list<name> names = mapper.selectlike(wildcardname); //这里是xml配置 <select id="selectlike"> select * from foo where bar like #{value} </select>
1
2
3
4
5
6
7第2种:在sql语句中拼接通配符,会引起sql注入
html// 这里是java代码 string wildcardname = "smi"; list<name> names = mapper.selectlike(wildcardname); //这里是xml配置 <select id=”selectlike”> select * from foo where bar like "%"${value}"%" </select>
1
2
3
4
5
6
7