1.应用示例
sql :
select * from ${table} where name= #{name} order by ${sort} desc
控制台信息:
2018-05-28 20:11:19.280 [http-nio-9090-exec-2] DEBUG com.hpu.mapper.UserMapper.findUser - ==> Preparing: select * from t_user where name= ? order by createtime desc
2018-05-28 20:11:19.593 [http-nio-9090-exec-2] DEBUG com.hpu.mapper.UserMapper.findUser - ==> Parameters: 管理员李四(String)
2018-05-28 20:11:19.764 [http-nio-9090-exec-2] DEBUG com.hpu.mapper.UserMapper.findUser - <== Total: 2
结论:
${table} 和 ${sort}在sql预编译阶段即替换为传入的值 t_user 和createtime
#{name} 在编译阶段使用占位符替换
$不加引号 #加入引号,$适用于 表名,排序字段等,
而#适用于 字段信息
注:如有不正确之处,欢迎指正