MyBatis ${} 和 #{} 区别
MyBatis 大约 437 字区别
${}
本质是字符串拼接
#{}
本质是占位符赋值
应用
#{}
可以防止SQL
注入,但有些场景还是需要${}
,比如如下查询语句,${}
就不会加上单引号(需注意MySQL
和PostgreSQL
对关键字加引号的处理不一致)。
select * from ${tableName}
模糊查询
MySQL
select * from user where username like "%"'keyword'"%"
MyBatis
使用#{}
占位
select * from user where username like "%"#{keyword}"%"
PostgreSQL
select * from "user" where username like CONCAT('%','keyword','%')
MyBatis
使用#{}
占位
select * from "user" where username like CONCAT('%',#{keyword},'%')
阅读 668 · 发布于 2022-09-11
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
pgAdmin4 Failed to open the system default web browser.Is one installed?.阅读 9521
-
Java WebSocket The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method阅读 5115
-
Spring Boot JPA 为数据表列 Column 添加注释阅读 1604
-
Kubernetes 获取容器 ID阅读 1342
-
Java 判断后缀是否匹配规则阅读 1969
-
Linux 之 CentOS yum 安装 Redis阅读 1453
-
软考-系统架构设计师:三级模式-两级映射阅读 1927
-
算法每日一题20190623:最长公共前缀阅读 2546
-
软考-系统架构设计师:企业资源计划(ERP)阅读 1775
-
Alpine Linux 查看发行版本阅读 347