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. sql
3 使用#能够很大程度上防止sql注入。(语句的拼接 #{xxx},使用的是PreparedStatement,会有类型转换,比较安全 简单的说就是#{}是通过预编译的,是安全的,${}是未通过预编译的,仅仅是取变量的值,是非安全的,存在SQL注入。)安全
4 可是若是使用在order by 中就须要使用 $.字符串
5 在大多数状况下仍是常用#,但在不一样状况下必须使用$.编译