博客
关于我
MyBatis——小知识:MyBatis_映射配置文件_参数值获取
阅读量:321 次
发布时间:2019-03-04

本文共 573 字,大约阅读时间需要 1 分钟。

#{}:可以获取map中的值或者pojo对象属性的值;

${}:可以获取map中的值或者pojo对象属性的值;

select * from employee where id=${id} and last_name=#{lastName}select * from ${tableName} where id=${id} and lastName=#{lastName}

Preparing: select * from employee where id=1 and last_name=?

Preparing: select * from employee where id=1 and lastName=?
上述两行都从控制台取出

区别:

#{}:是以预编译的形式,将参数设置到sql语句中;PreparedStatement;防止sql注入
${}:取出的值直接拼装在sql语句中;会有安全问题;
大多情况下,我们去参数的值都应该去使用#{};

原生jdbc不支持占位符的地方我们就可以使用${}进行取值	比如分表、排序。。。;按照年份分表拆分		select * from ${year}_salary where xxx;		select * from tbl_employee order by ${f_name} ${order}

转载地址:http://mqqq.baihongyu.com/

你可能感兴趣的文章
Netty WebSocket客户端
查看>>
netty 主要组件+黏包半包+rpc框架+源码透析
查看>>
Vue过渡 & 动画---vue工作笔记0014
查看>>
Netty 异步任务调度与异步线程池
查看>>
Netty 的 Handler 链调用机制
查看>>
Netty 编解码器和 Handler 调用机制
查看>>
Netty 编解码器详解
查看>>
Netty 解决TCP粘包/半包使用
查看>>
Netty 调用,效率这么低还用啥?
查看>>
Netty 高性能架构设计
查看>>
Netty+Protostuff实现单机压测秒级接收35万个对象实践经验分享
查看>>
Netty+SpringBoot+FastDFS+Html5实现聊天App详解(一)
查看>>
netty--helloword程序
查看>>
netty2---服务端和客户端
查看>>
【Flink】Flink 2023 Flink易用性和稳定性在Shopee的优化-视频笔记
查看>>
Netty5.x 和3.x、4.x的区别及注意事项(官方翻译)
查看>>