mybatis$和#的区别

select * from everstar.Questions where ProductType = 'productType'
select * from everstar.Questions where ProductType = '${productType}'
select * from everstar.Questions where ProductType = #{productType}

最直观的区别就是${}取出来的值直接就是传过来的数据,对于字符串而言需要加''单引号

用过jdbcTemplate的人应该知道,${}就类似于execute()而#{}类似于update().

#{}跟jdbc的prepareStatement是一样的道理。

跟hibernate的setParameter是一个吊样,都可以防止sql注入。

而#{}取值会默认加'',会根据类型来判断的。

 ${ } 变量的替换阶段是在动态 SQL 解析阶段,而 #{ }变量的替换是在 DBMS 中。

  • #方式能够很大程度防止sql注入。
  • $方式无法防止Sql注入。
  • $方式一般用于传入数据库对象,例如传入表名.

mybatis会用到的所有标签

图片总结很到位,具体用法  (ゝω・) テヘペロ  mybatis全部标签

原文地址:https://www.cnblogs.com/chywx/p/9448467.html