#{}占位符的使用:
#{}在传入参数时相当于传入了字符串 eg:select * from table_name where id=#{id};
#{}在传入参数为1时,相当于传入了字符串 eg:select * from table_Name where id=‘1’;
${}占位符的使用:
在
传
入
参
数
时
是
把
原
值
传
入
e
g
:
s
e
l
e
c
t
∗
f
r
o
m
t
a
b
l
e
n
a
m
e
w
h
e
r
e
i
d
=
{}在传入参数时是把原值传入 eg: select * from table_name where id=
在传入参数时是把原值传入eg:select∗fromtablenamewhereid={id};
${}在传入参数为1时 eg: select * from table_name where id=1;
区别:
#{}传入参数是以字符串传入,可以有效的防止SQL注入攻击,相当于JDBC中的preparedStatement预编译
${}传入参数是原值传入,可能会出现SQL注入攻击,相当于JDBC中的Statement编译
#{}和${}的区别
最新推荐文章于 2021-11-07 21:33:54 发布