${ }是字符串替换,相当于直接显示数据,#{ }是预编译处理,相当于对数据加上双引号

即#是将传入的值当做字符串的形式,先替换为?号,然后调用PreparedStatement的set方法来赋值,而$是将传入的数据直接显示生成sql语句

--Mybatis在处理#{}时
select id,name,age from student where id =#{id}
当前端把id值1传入到后台的时候,就相当于:
select id,name,age from student where id ='1'

--Mybatis在处理${}时
select id,name,age from student where id =${id}
当前端把id值1传入到后台的时候,就相当于:
select id,name,age from student where id = 1

使用#{ }可以有效的防止SQL注入,提高系统安全性(语句的拼接),如果使用在order by 中就需要使用 ${ }。

最大区别在于:#{ } 传入值时,sql解析参数是带引号的,而${ }传入值时,sql解析参数是不带引号的。

相关文章:

  • 2021-09-23
  • 2021-08-27
  • 2021-08-21
  • 2021-11-24
  • 2021-10-31
  • 2021-06-07
  • 2021-11-07
  • 2022-12-23
猜你喜欢
  • 2021-10-25
  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-07-15
相关资源
相似解决方案