mybatise#{}如何防止sql注入
1、#{}是预编译处理是一个占位符,mybatis遇见#{}时,会将sql中的#{}替换为?号。
select * from table where id=#{id}
当id我们传值为101时,
mybatise将预编译为
select * from table where id=?
最终执行的sql为
select * from table where id='101'
2、$ {}是字符串替换,,调用PreparedStatement的set方法来赋值;mybatis在处理时 ,就 是 把 {}替换成变量的值。使用#{}可以有效的防止SQL注入,提高系统安全性。
select * from table where id=${id}
当id传值为101时
mybatise将sql转换为
select * from table where id=101
3、#{}将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号。
4、${}将传入的数据直接显示生成在sql中。
待续。。。
本文来自博客园,作者:陈浩文,转载请注明原文链接:https://www.cnblogs.com/chenhaowen/p/16627854.html

浙公网安备 33010602011771号