`
xudongcsharp
  • 浏览: 468331 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

ibatis 防止SQL注入与占位符的注入

 
阅读更多

SQL注入:

如果用户执行
select * from product where id = 5
这条语句。其中5是有用户输入的。
SQL注入的含义就是,一些捣蛋用户输入的不是5,而是
5;  delete  from  orders
那么原来的SQL语句将会变为,
select * from product where id=5;  delete  from  orders
在执行完select后,还将删除orders表里的所有记录。

不过庆幸的是,Ibatis使用的是预编译语句PreparedStatements
上述语句会被编译为,
select * from product where id=?
从而有效防止SQL注入。

不过当你使用$占位符时就要注意了。

#与$区别:
#xxx# 代表xxx是属性值,map里面的key或者是你的pojo对象里面的属性, ibatis会自动在它的外面加上引号,表现在sql语句是这样的 where xxx = 'xxx' ;

$xxx$ 则是把xxx作为字符串拼接到你的sql语句中, 比如 order by topicId , 语句这样写 ... order by #xxx# ibatis 就会把他翻译成 order by 'topicId' (这样就会报错) 语句这样写 ... order by $xxx$ ibatis 就会把他翻译成 order by topicId
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics