${}
解析传过来的参数值不带单引号
如select * from table where id = ${id}
解析为select * from table where id =1
#{}
解析传过来的参数值带单元号
如select * from table where id = #{id}
解析为select * from table where id ='1'
通常使用#{}
用于传入参数值,可以防止 SQL 注入,提高安全性。如果传入的参数是表名或字段名等常量字符串,如 order by 后面的参数,就要使用${}
来传入参数了。