mybatis中条件查询的预编译符号

编程入门 行业动态 更新时间:2024-10-09 12:33:47

mybatis中条件查询的预编译<a href=https://www.elefans.com/category/jswz/34/1770893.html style=符号"/>

mybatis中条件查询的预编译符号

在mybatis中#{}代表预编译,可以防止sql注入,而${}相反

@Select("select * from emp where name like '%#{name}%' and gender =#{gender} and " +"entrydate between #{begin} and #{end} order by update_time desc ")public List<Emp> list (String name, Short gender, LocalDate begin,LocalDate end);

 %#{name}%预编译会导致sql编译出错需要换成%${name}%,而%${name}%性能低,不安全,存在sql注入问题,此时可以使用mysql的concat()指令替换.

concat('%',#{name},'%')
// 条件查询@Select("select * from emp where name like '%${name}%' and gender =#{gender} and " +"entrydate between #{begin} and #{end} order by update_time desc ")public List<Emp> list (String name, Short gender, LocalDate begin,LocalDate end);
@Select("select * from emp where name like concat('%',#{name},'%') and gender =#{gender} and " +"entrydate between #{begin} and #{end} order by update_time desc ")public List<Emp> list (String name, Short gender, LocalDate begin,LocalDate end);

 

更多推荐

mybatis中条件查询的预编译符号

本文发布于:2024-02-13 04:54:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1690768.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:符号   条件   mybatis

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!