模糊查询 like 语句该怎么写?

发布于 2021-05-10 17:55:52
关注者
0
被浏览
605
1 个回答
  • 面试哥
    面试哥 2021-05-10
    为面试而生,有面试问题,就找面试哥。

    第 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>
    
知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看