博客
关于我
MyBatis——小知识:MyBatis_映射配置文件_参数值获取
阅读量:318 次
发布时间: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/

你可能感兴趣的文章
【单片机开发】基于stm32的掌上游戏机设计 (项目规划)
查看>>
KeepAlived介绍、配置示例、KeepAlived配置IPVS、调用脚本进行监控
查看>>
【Numpy学习】np.count_nonzero()用法解析
查看>>
Scala集合-数组、元组
查看>>
JAVA网络爬虫01-http client爬取网络内容
查看>>
04 程序流程控制
查看>>
java并发编程(1)
查看>>
C++&&STL
查看>>
子集(LeetCode 78)
查看>>
1004 Counting Leaves (30分)
查看>>
1093 Count PAT‘s (25分) 含DP做法
查看>>
一篇解决JMM与volatile详解(二)
查看>>
数据结构之数组与经典面试题(二)
查看>>
无锁并发框架-Disruptor的使用(二)
查看>>
Android wm命令
查看>>
boot.img 解包与打包
查看>>
Android4.4 平板背光设置
查看>>
spring boot@Value和bean执行顺序问题
查看>>
codeforces The Eternal Immortality 题解
查看>>
蓝桥杯 历届试题 幸运数 (堆+DFS)
查看>>