#{}和${}的区别?

  • #{}是占位符,预编译处理;${}是拼接符,字符串替换,没有预编译处理。
  • Mybatis在处理#{}时,#{}传入参数是以字符串传入,会将SQL中的#{}替换为?号,调用PreparedStatement的set方法来赋值。
  • Mybatis在处理时 , 是 原 值 传 入 , 就 是 把 {}时,是原值传入,就是把时,是原值传入,就是把{}替换成变量的值,相当于JDBC中的Statement编译
  • 变量替换后,#{} 对应的变量自动加上单引号 '';变量替换后,${} 对应的变量不会加上单引号 ''
  • #{} 可以有效的防止SQL注入,提高系统安全性;${} 不能防止SQL 注入
  • #{} 的变量替换是在DBMS 中;${} 的变量替换是在 DBMS 外
相关推荐
lbb 小魔仙3 小时前
MyBatis-Plus 系统化实战:从基础 CRUD 到高级查询与性能优化
java·性能优化·mybatis
tb_first17 小时前
SSM速通3
java·jvm·spring boot·mybatis
tb_first18 小时前
SSM速通4
java·jvm·spring·tomcat·maven·mybatis
程可爱19 小时前
springboot整合mybatis和postgresql
spring boot·postgresql·mybatis
risc12345620 小时前
【Elasticsearch】LeafDocLookup 详述
大数据·elasticsearch·mybatis
李少兄1 天前
解决 org.springframework.context.annotation.ConflictingBeanDefinitionException 报错
java·spring boot·mybatis
一只大袋鼠1 天前
分布式 ID 生成:雪花算法原理、实现与 MyBatis-Plus 实战
分布式·算法·mybatis
码农小卡拉1 天前
MyBatis-Flex 全面解析与实战教程:轻量高效的 MyBatis 增强方案
java·mybatis
弓弧名家_玄真君1 天前
在ubuntu中安装redis
前端·bootstrap·mybatis
qq_5470261792 天前
Redis 常见问题
数据库·redis·mybatis