MyBatis(3.2.3) - ResultMaps: Extending ResultMaps
ResultMaps are used to map the SQL SELECT statement's results to JavaBeans properties. We can define ResultMaps and reference this resultMap query from
several SELECT statements.
We can extend one <resultMap> query from another <resultMap> query, thereby inheriting the column to do property mappings from the one that is being extended.
<resultMap type="Student" id="StudentResult">
<id property="studId" column="stud_id"/>
<result property="name" column="name"/>
<result property="email" column="email"/>
<result property="phone" column="phone"/>
</resultMap> <resultMap type="Student" id="StudentWithAddressResult" extends="StudentResult">
<result property="address.addrId" column="addr_id"/>
<result property="address.street" column="street"/>
<result property="address.city" column="city"/>
<result property="address.state" column="state"/>
<result property="address.zip" column="zip"/>
<result property="address.country" column="country"/>
</resultMap>
The resultMap query with the ID StudentWithAddressResult extends the resultMap with the ID StudentResult.
Now you can use StudentResult resultMap if you want to map only the Student data as shown in the following code:
<select id="findStudentById" parameterType="int" resultMap="StudentResult">
SELECT * FROM STUDENTS WHERE STUD_ID=#{studId}
</select>
If you want to map the query results with Student along with the Address data, you can use resultMap with the ID StudentWithAddressResult as follows:
<select id="selectStudentWithAddress" parameterType="int" resultMap="StudentWithAddressResult">
SELECT STUD_ID, NAME, EMAIL, PHONE, A.ADDR_ID, STREET, CITY, STATE, ZIP, COUNTRY
FROM STUDENTS S LEFT OUTER JOIN ADDRESSES A
ON S.ADDR_ID = A.ADDR_ID
WHERE STUD_ID = #{studId}
</select>
MyBatis(3.2.3) - ResultMaps: Extending ResultMaps的更多相关文章
- 关于mybatis的思考(3)——ResultMaps的使用
ResultMap元素在mybatis中非常重要,目的是告诉mybatis将从结果集中取出的数据转换为开发者需要的对象. UserMapping.xml <!-- selectAll操作 ...
- Table of Contents - MyBatis
Getting Started with MyBatis Hello World Integration with Spring Bootstrapping MyBatis Configuring M ...
- 【MyBatis源码分析】Configuration加载(下篇)
元素设置 继续MyBatis的Configuration加载源码分析: private void parseConfiguration(XNode root) { try { Properties s ...
- Mybatis源码分析之结果集处理
解析封装 ResultMap 是和结果集相关的东西,最初在解析 XML 的时候,于 parseStatementNode 方法中,针对每一个 select 节点进行解析,转换为 MappedState ...
- Java Persistence with MyBatis 3(中文版) 第三章 使用XML配置SQL映射器
关系型数据库和SQL是经受时间考验和验证的数据存储机制.和其他的ORM 框架如Hibernate不同,MyBatis鼓励开发者可以直接使用数据库,而不是将其对开发者隐藏,因为这样可以充分发挥数据库服务 ...
- Mybaits 源码解析 (三)----- Mapper接口底层原理(为什么Mapper不用写实现类就能访问到数据库?)
上一篇我们讲解到mapperElement方法用来解析mapper,我们这篇文章具体来看看mapper.xml的解析过程 mappers配置方式 mappers 标签下有许多 mapper 标签,每一 ...
- IBatisNet基础组件
DomSqlMapBuilder DomSqlMapBuilder,其作用是根据配置文件创建SqlMap实例.可以通过这个组件从Stream, Uri, FileInfo, or XmlDocumen ...
- IbatisNet开发使用小结
一. 介绍 平常做企业级应用,需求变化是经常的事,而很多基础代码重复也是很让人头疼的问题.所以很多人会使用一些ORM框架来增强项目的可维护性.可扩展性.IBatis.Net就是一个比较易用的ORM ...
- Mybatis逆向工程 —— ResultMaps collection already contains value for ***
报错提示: Result Maps collection already contains value for ***. 遭遇场景: maven+ssm 项目中,采用了mybatis的逆向工程生成 p ...
随机推荐
- ssi整合报错org.apache.struts2.convention.ConventionsServiceImpl.determineResultPath(ConventionsServiceImpl.java:100)
java.lang.RuntimeException: Invalid action class configuration that references an unknown class name ...
- Http通讯协议在.net下的实现方法
1.HttpwebRequest and HttpWebResponse 2.客户端访问服务端的API:HttpClient 3. .net下的Remoting 4.Web Services 5.W ...
- 怀念我的老师——丁伟岳院士 by 史宇光
在我的人生中,丁老师对我的帮助是莫大的. 我第一次见到丁老师是在91年8月份的一次南开非线性分析学术会议上(会议期间苏联发生了8.19事件),他当时报告的题目是关于二维调和映射热流短时间爆破的问 ...
- 安装centreon
Centreon + nagios + ndoutils 安装 2013-09-25 19:42:44 标签:centreon 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者 ...
- Failed to load session “ubuntu” -- 12.04
在使用ubuntu 12.04的时候,之前不喜欢Unity桌面,就按照网上提示的安装了Gnome桌面,并且成功了! 可是,最近又想把Unity装回来,心想,这不就是安装一软件的活嘛,很简单!于是就卸载 ...
- 使用Unity制作游戏关卡的教程(三)
转自:http://gamerboom.com/archives/75593 作者:Matthias Zarzecki 本文是“使用Unity制作<The Fork Of Truth>的关 ...
- 【转】Java判断是否是整数,小数或实数的正则表达式
经常会遇到这样的情况,需要判断一个字符串是否是一个合法的数,包括整数,小数或者实数. 网上查到很多文章大多是判断这个字符串是否全为数字,比如下面这段来自StringUtils的代码,可以看到,13.2 ...
- 通过注册表查看已安装 .NetFramework 版本
gci "hklm:\SOFTWARE\Microsoft\NET Framework Setup\NDP" | % {(Get-ItemProperty registry::$_ ...
- Qt编程18:Qt调色板QPalette的使用
QPalette类有两个枚举类型, 枚举 1.ColorGroup CorGroup指的是3中不同的状态(什么时候设置颜色): 1>Active:获得焦点的状态. 2>Inactive:未 ...
- WCF与WebService之间的异同
下面我们来详细讨论一下二者的区别.Web Service和WCF的到底有什么区别. 1,Web Service:严格来说是行业标准,也就是Web Service 规范,也称作WS-*规范,既不是框架, ...