MyBatis ${} 和 #{} 区别
MyBatis About 437 words区别
${}本质是字符串拼接
#{}本质是占位符赋值
应用
#{}可以防止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},'%')
                Views: 1,975 · Posted: 2022-09-10
            
            ————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
        Loading...