默认情况下,使用#{}语法,MyBatis会产生PreparedStatement语句中,并且安全的设置PreparedStatement参数,这个过程中MyBatis会进行必要的安全检查和转义. #相当于对数据 加上 双引号,$相当于直接显示数据 示例1:执行SQL:select * from emp where name = #{employeeName}参数:employeeName=>Smith解析后执行的SQL:select * from emp where name = ? 示例2:
mybatis是如何防止SQL注入的 1.首先看一下下面两个sql语句的区别: <select id="selectByNameAndPassword" parameterType="java.util.Map" resultMap="BaseResultMap"> select id, username, password, role from user where username = #{username,jdbcType=VA
1.判断是否可以注入: 数字型: 1.1在参数后面加一个引号',如果页面报数字number错误,则一定不是sql注入点:如果报数据库比如mysql.oracle之类的错误,则是一个sql注入点. 1.2 在参数后面加上 依次加上 and 1=1 和 and 1=2,如果加上 and 1=1 还能正常显示原来的数据,并且加上 and 1=2时,原来数据不显示或者报错时,则是一个sql注入点 字符型: 1.3 在参数后面加上 依次加上 ' and '1'='1 和 ' and '1'='2 ,如果加