一、使用:
#{}: 解析为一个 JDBC 预编译语句(prepared statement)的参数标记符,一个 #{ } 被解析为一个参数占位符 。
${}: 仅仅为一个纯碎的 string 替换,在动态 SQL 解析阶段将会进行变量替换。
name-->cy
eg: select id,name,age from student where name=#{name} -- name='cy'
select id,name,age from student where name=${name} -- name=cy
二、区别:
1. #是将传入的值当做字符串的形式,$是将传入的数据直接显示生成sql语句。
2. 使用#可以很大程度上防止sql注入,而$却不能。
3. 但是如果使用在order by 中就需要使用 $。
4. 尽可能使用#。
转载于:https://www.cnblogs.com/chenloveslife/p/9535385.html