博客
关于我
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/

你可能感兴趣的文章
MySQL的 DDL和DML和DQL的基本语法
查看>>
mysql的 if else , case when then, IFNULL
查看>>
MySQL的10种常用数据类型
查看>>
MySQL的btree索引和hash索引的区别
查看>>
mysql的cast函数
查看>>
MySql的CRUD(增、删、改、查)操作
查看>>
MySQL的DATE_FORMAT()函数将Date转为字符串
查看>>
mysql的decimal与Java的BigDecimal用法
查看>>
MySql的Delete、Truncate、Drop分析
查看>>
MySQL的Geometry数据处理之WKB方案
查看>>
MySQL的Geometry数据处理之WKT方案
查看>>
mysql的grant用法
查看>>
Mysql的InnoDB引擎的表锁与行锁
查看>>
mysql的InnoDB引擎索引为什么使用B+Tree
查看>>
MySQL的InnoDB默认隔离级别为 Repeatable read(可重复读)为啥能解决幻读问题?
查看>>
MySQL的insert-on-duplicate语句详解
查看>>
mysql的logrotate脚本
查看>>
MySQL的my.cnf文件(解决5.7.18下没有my-default.cnf)
查看>>
MySQL的on duplicate key update 的使用
查看>>
MySQL的Replace用法详解
查看>>