mybatis中#{}和${}的区别
mybatis本身的说明: By default,using the #{} syntax will cause MyBatis to generate PreparedStatement properties and set the values safely against the PreparedStatement parameters (e.g. ?). While this is safer,faster and almost always preferred,sometimes you just want to directly inject a string unmodified into the SQL Statement. For example,for ORDER BY,<span style="color: #000000;"> you might use something like this:ORDER BY ${columnName} NOTE It's not safe to accept input from a user and supply it to a statement unmodified in this way. This leads to potential SQL Injection attacks and therefore you should either disallow user input in these fields,or always perform your own escapes and checks. 从上文可以看出: 1. 使用#{}格式的语法在mybatis中使用Preparement语句来安全的设置值,执行sql类似下面的: PreparedStatement ps =1,id);此时MyBatis 不会修改或转义字符串。 这种方式类似于: Statement st = ResultSet rs </span>= st.executeQuery(sql);</pre>
参考文献: 【1】http://mybatis.github.io/mybatis-3/sqlmap-xml.html 【2】https://mybatis.github.io/mybatis-3/zh/sqlmap-xml.html (编辑:台州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- MySQL – 无法使用SET变量创建视图
- mysql – ActiveRecord在Ruby 1.9.2-rc1下以ASCII-8Bit返回
- mysql – 最大SQL连接表数限制是否适用于整个查询,还是单独
- mysql – 选择类似的IP地址 – 忽略最后3位数
- 从MySQL WorkBench中的SQL脚本生成图表
- 如何把8千多万日志数据入库?---同事的分享[开发篇]
- php – SQL和Case Insensitive条件
- java – 用hibernate锁定表
- MySQL存储函数与嵌套IF … END IF,语法错误,正确的语法使用
- mysql – 模式迁移:PostgreSQL中的一对多,多对多