1 #是将传入的值当做字符串的形式,eg:select id,name,age from student where id =#{id},当前端把id值1,传入到后台的时候,就相当于 select id,name,age from student where id ='1'.

 2 $是将传入的数据直接显示生成sql语句,eg:select id,name,age from student where id =${id},当前端把id值1,传入到后台的时候,就相当于 select id,name,age from student where id = 1.

 3 使用#可以很大程度上防止sql注入。(语句的拼接  #{xxx},使用的是PreparedStatement,会有类型转换,比较安全 简单的说就是#{}是经过预编译的,是安全的,${}是未经过预编译的,仅仅是取变量的值,是非安全的,存在SQL注入。)

 4 但是如果使用在order by 中就需要使用 $.

 5 在大多数情况下还是经常使用#,但在不同情况下必须使用$. 

相关文章:

  • 2022-12-23
  • 2021-07-14
  • 2021-11-13
  • 2021-11-24
  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-21
  • 2022-12-23
  • 2021-06-27
  • 2021-09-01
  • 2021-07-17
相关资源
相似解决方案