1:#是将传入的值当作字符串的形式sql
例如 :select * from 表名 where id =#{id}mybatis
解析:select* from student where id ='1'.spa
2 :$是将传入的数据直接显示生成sql语句字符串
例如 :select * from 表名 where id =${id}string
解析:select* from student where id =1.it
3 :使用#能够很大程度上防止sql注入。(语句的拼接)编译
4: 可是若是使用在order by 中就须要使用 $.变量
5 :在大多数状况下仍是常用#,但在不一样状况下必须使用$. select
#与$ 的区别最大在于:#{} 传入值时,sql解析时,参数是带引号的,而sql语句
${} 传入值时,sql解析时,参水是不带引号的。
在mybatis中的$与#都是在sql中动态的传入参数。
#{}: 解析为一个 JDBC 预编译语句(prepared statement)的参数标记符(?),一个 #{ } 被解析为一个参数 占位符 。
${}: 仅仅为一个纯碎的 string 替换,在动态 SQL 解析阶段将会进行变量替换。
例如: select * from student where name=#{value} -- name='cy'
select * from student where name=${value} -- name=cy
若是是 参数 通常使用 #{} 例如 字段,limit 的也可以使用
若是是 sql 自己条件为动态,使用 ${} 例如 order by ,limit 的也可以使用
Interger 类型 均可使用,String 类型请慎重!