您的位置:首页 > 数据库

MyBatis 模糊查询 防止Sql注入

2018-03-06 15:56 471 查看
#{xxx},使用的是PreparedStatement,会有类型转换,所以比较安全;

${xxx},使用字符串拼接,可以SQL注入;

like查询不小心会有漏洞,正确写法如下:

Mysql:  

[sql] view
plain copy

select * from t_user where name like concat('%', #{name}, '%')    

Oracle: 

[sql] view
plain copy

select * from t_user where name like '%' || #{name} || '%'  

SQLServer: 

[sql] view
plain copy

select * from t_user where name like '%' + #{name} + '%'  

转载地址:http://blog.csdn.net/pange1991/article/details/47810187
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle