【MyBatis】resultMap和resultType的区别
mybatis中resultMap和resultType的区别
mybatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMap。resultType是直接表示返回类型的,而resultMap则是对外部ResultMap的引用,但是resultType跟resultMap不能同时存在。
public class User {
private int id;
private String username;
private String hashedPassword;
//省略setter/getter方法
}
- 使用resultType
<select id="selectUsers" parameterType="int" resultType="com.someapp.model.User">
select id, username, hashedPassword
from some_table
where id = #{id}
</select>
这些情况下,MyBatis 会在幕后自动创建一个 ResultMap,基于属性名来映射列到 JavaBean 的属性上。如果列名没有精确匹配,可以在列名上使用 select 字句的别名来匹配标签。
- 使用resultMap
<resultMap id="userResultMap" type="User">
<id property="id" column="user_id" />
<result property="username" column="username"/>
<result property="password" column="password"/>
</resultMap>
<select id="selectUsers" parameterType="int" resultMap="userResultMap">
select user_id, user_name, hashed_password
from some_table
where id = #{id}
</select>
- 不同
- resultType对应的是java对象中的属性,大小写不敏感;resultMap对应的是对已经定义好了id的resultTupe的引用,key是查询语句的列名,value是查询的值,大小写敏感;
- 使用resultType的时候,要保证结果集的列名与java对象的属性相同,而resultMap则不用。
- 另外,resultMap 元素,它是 MyBatis 中最重要最强大的元素,它能提供级联查询,缓存等功能。
【MyBatis】resultMap和resultType的区别相关推荐
- php 数据类型 map,ResultMap和ResultType的区别
ResultMap和ResultType的区别 使用mybatis进行数据库连接操作时对于SQL语句返回结果的处理通常有两种方式,一种就是resultType:另一种就是resultMap: 1.re ...
- resultMap与resultType的区别
resultmap与resulttype的区别为:对象不同.描述不同.类型适用不同. 一.对象不同 1.resultmap:resultMap如果查询出来的列名和pojo的属性名不一致,通过定义一个r ...
- resultMap和resultType 的区别?
1.resultMap 如果查询出来的列名和pojo的属性名不一致时,可以通过resultMap对列名和属性名做映射关系; <resultMap type="com.wuhao.one ...
- 在mybatis中resultMap与resultType的区别
MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMap resultType是直接表示返回类型的,而resultMap则是对外部ResultM ...
- Mybatis中resultMap和resultType的区别
MyBatis的每一个查询映射的返回类型都是ResultMap,只是当我们提供的返回类型属性是resultType的时候,MyBatis对自动的给我们把对应的值赋给resultType所指定对象的属性 ...
- mybatis Resultmap 与 ResultType 区别
Resultmap 的写法====目的是为了做映射 <resultMap id="BaseResultMap"type="com.suning.jupiter.co ...
- resultMap和resultType的区别
resultMap返回的列名与bean的属性名可以不一致,resultType则要求一致.就具体代码作分析.对于指定resultMap属性,直接读取字符串,而对于指定resultType会解析为具体的 ...
- ibatis中resultMap和resultType使用区别
resultMap 1.resultMap的值为映射的返回值自定义节点Id名称 resultType 1.resultType的值为返回值的类型,且为一列 ---------------------- ...
- mybatis中resultMap和resultType区别,三分钟读懂
先说结论: resultmap与resulttype的区别为:对象不同.描述不同.类型适用不同. 说人话就是,resultmap和resulttype功能差不多,但是resultmap功能更强大 re ...
最新文章
- python二进制转字符串
- 【转】算法中时间复杂度概括——o(1)、o(n)、o(logn)、o(nlogn)
- TColorToHex 与 HexToTColor
- Python常见面试题:TCP 协议中的三次握手与四次挥手相关概念详解
- 【视频】CCNA——telnet和SSH的配置
- Chapter7-8_Deep Learning for Constituency Parsing
- linux嵌入式物联网_嵌入式Linux如何加速物联网发展
- JS控制文本框内键盘上下左右键的焦点
- Spring源码之FactoryBean接口的作用和实现原理
- 【领英如何一键批量有效地加好友?】
- 什么是CSR以及CSR的作用和生成方法
- 海康威视相机开发(一)
- 月均播放超2.8亿,vlog会是品牌B站推广新风口吗?
- 分布式架构、大数据、机器学习、搜索、推荐、广告
- android rsa加密工具类,GitHub - Lerist/encrypt: Android 加密解密工具包。
- 3418 杨辉三角形(找规律 + 二分)
- 个人也可以通过维瑞申请VeriSign,Thawte 代码签名证书
- openwrt winshak 抓取无线beacon帧
- Vue_单页应用VS多页应用
- C++ STL源码分析——一个万用的 hash function