${} 与 #{} 的区别
区别#{}是预编译处理,${}是字符串替换。mybatis处理#{}时,将#{}替换成?,调用PreparedStatement的set方法赋值,这种预编译的机制可以很大程度防止SQL注入;处理${}时,直接进行字符串的替换,无法防止SQL注入。#{}解析后会将String类型的数据自动加上引号,${}不会。例如: select * from student where sname = #{sname} select * from student where sname = '${va
复制链接