MyBatis 模糊查询 防止Sql注入

#{xxx},使用的是PreparedStatement,会有类型转换,所以比较安全;
${xxx},使用字符串拼接,可以SQL注入;
like查询不小心会有漏洞,正确写法如下:

Mysql:  
[sql]  view plain  copy
  1. select * from t_user where name like concat('%', #{name}, '%')    

Oracle: 
[sql]  view plain  copy
  1. select * from t_user where name like '%' || #{name} || '%'  

SQLServer: 
[sql]  view plain  copy
  1. select * from t_user where name like '%' + #{name} + '%'  


转载地址:http://blog.csdn.net/pange1991/article/details/47810187

猜你喜欢

转载自blog.csdn.net/u014344668/article/details/79459510