File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed
docs/system-design/framework/mybatis Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change 2525
2626答:
2727
28- - ` ${} ` 是 Properties 文件中的变量占位符,它可以用于标签属性值和 sql 内部,属于静态文本替换,比如\$ {driver}会被静态替换为` com.mysql.jdbc. Driver ` 。
28+ - ` ${} ` 是 Properties 文件中的变量占位符,它可以用于标签属性值和 sql 内部,属于原样文本替换,可以替换任意内容,比如\$ {driver}会被原样替换为` com.mysql.jdbc. Driver ` 。
29+ 一个实例:根据参数按任意字段排序:
30+ ``` sql
31+ select * from users order by ${orderCols}
32+ ```
33+ ` orderCols ` 可以是 ` name ` 、` name desc ` 、` name,sex asc ` 等,实现灵活的排序。
34+
2935- ` #{} ` 是 sql 的参数占位符,MyBatis 会将 sql 中的` #{} ` 替换为? 号,在 sql 执行前会使用 PreparedStatement 的参数设置方法,按序给 sql 的? 号占位符设置参数值,比如 ps.setInt(0, parameterValue),` #{item.name} ` 的取值方式为使用反射从参数对象中获取 item 对象的 name 属性值,相当于 ` param.getItem().getName() ` 。
3036
3137### xml 映射文件中,除了常见的 select、insert、update、delete 标签之外,还有哪些标签?
You can’t perform that action at this time.
0 commit comments