#{}与${}

#{}与${}

1、#{}:表示占位符?,可以有效防止sql注入。使用#{}设置参数无需考虑参数的类型。PreparedStatement

2、${}:表示拼接符,无法防止sql注入。使用${}设置参数必须考虑参数的类型。Statement

3、传递简单类型参数

​ a、如果获取简单类型参数,#{}中可以使用value或其他名称。

​ b、如果获取简单类型参数,${}中只能使用value。

​ 注意引号的引入

​ select * from tbl_student where id = '${value}'

4、没有特殊情况下,通常使用#{}占位符

5、有些情况必须使用${},

​ 比如:需要动态拼接表名,select * from ${tablename},

​ 比如:动态拼接排序字段:select * from tablename order by ${username} desc

posted @ 2021-07-31 19:39  初中生林开心  阅读(72)  评论(0)    收藏  举报