mybatis学习 十四 resultMap标签 一对一(联合查询)
1.使用 resultMap 实现关联单个对象(联合查询方式)
<resultMap type="Student" id="stuMap1">
<id column="sid" property="id"/>
<result column="sname" property="name"/>
<result column="age" property="age"/>
<result column="tid" property="tid"/>
<association property="teacher" javaType="Teacher" > <id column="tid" property="id"/>
<result column="tname" property="name"/>
</association>
</resultMap> <select id="selAll1" resultMap="stuMap1">
select s.id sid,s.name sname,age age,t.id tid,t.name tname FROM student s left outer join teacher t on s.tid=t.id
</select>
注意id为selAll1的select标签与下面id为selAll的select标签的区别
<resultMap type="student" id="stuMap">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="age" property="age"/>
<result column="tid" property="tid"/>
<association property="teacher" javaType="Teacher" column="tid" select="com.xxx.mapper.TeacherMapper.selById" >
</association>
</resultMap>
<select id="selAll" resultMap="stuMap">
select * from student
</select>
第一中是联合查询,第二中不是,是先查询每一个学生,然后再根据学生的tid去查询老师,第二种实现效率低
mybatis学习 十四 resultMap标签 一对一(联合查询)的更多相关文章
- mybatis学习 十五 resultMap标签 一对多
多次查询,非联合查询版本 <resultMap type="teacher" id="techMap"> <id column="i ...
- mybatis学习 十六 auto_mapping实现连表查询
只能使用多表联合查询方式. 要求:查询出的列别和属性名相同. 点字符 "." 在 SQL 是关键字符,两侧添加反单引号(Tab键上的一个字符) <select id=&q ...
- MyBatis学习 之 四、MyBatis配置文件
目录(?)[-] 四MyBatis主配置文件 properties属性 settings设置 typeAliases类型别名 typeHandlers类型句柄 ObjectFactory对象工厂 pl ...
- 【转】MyBatis学习总结(四)——解决字段名与实体类属性名不相同的冲突
[转]MyBatis学习总结(四)——解决字段名与实体类属性名不相同的冲突 在平时的开发中,我们表中的字段名和表对应实体类的属性名称不一定都是完全相同的,下面来演示一下这种情况下的如何解决字段名与实体 ...
- mybatis学习 十三 resultMap标签 一对一
1 .<resultMap>标签 写在mapper.xml中,由程序员控制SQL查询结果与实体类的映射关系. 在写<select>标签中,有一个resultType属性,此时s ...
- Mybatis学习(四)————— 高级映射,一对一,一对多,多对多映射
一.单向和双向 包括一对一,一对多,多对多这三种情况,但是每一种又分为单向和双向,在hibernate中我们就详细解析过这单向和双向是啥意思,在这里,在重复一遍,就拿一对多这种关系来讲,比如有员工和部 ...
- MyBatis学习(四)MyBatis一对一关联查询
一对一关联查询即.两张表通过外键进行关联.从而达到查询外键直接获得两张表的信息.本文基于业务拓展类的方式实现. 项目骨架 配置文件conf.xml和db.properties前几节讲过.这里就不细说了 ...
- MyBatis的学习总结四:实现关联表查询【参考】
一.一对一的表关联查询(edi_test_task 和 edi_task_detail) 例子:一条任务明细对一条任务记录 对应的sql的映射xml文件如下: <?xml version=& ...
- mybatis学习 十二 多表查询
Mybatis 实现多表查询方式: (1)业务装配.对两个表编写单表查询语句,在业务(Service)把查询的两个结果进行关联. (2)使用Auto Mapping特性,在实现两表联合查询时通过别名完 ...
随机推荐
- oracle 中更新update不成功的原因
oracle 中执行insert into 与delete 都正常,但是执行update 却没有反应. 原因: 是因为记录锁.这种只有update无法执行其他语句可以执行的其实是因为记录锁导致的,在o ...
- SpringCloud报错: "Field discoveryClient in com.controller.DcController required a bean of type 'com.netflix.discovery.DiscoveryClient' that could not be found."
SpringCloud报错: "Field discoveryClient in com.controller.DcController required a bean of type 'c ...
- 关于CDh5.13.1 HDFS启用HA(High Availability)注意事情--(JournalNode 只有一个编辑路径)
原因为:主机名不能为域名.更换成hadoop64 这种解决.
- 51nod 1163 最高的奖励
链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1163 1163 最高的奖励 基准时间限制:1 秒 空间限制:13 ...
- js 小结
<script type="text/javascript"> var hotalAddJs = { makeSubmitDataHandler: function ( ...
- HDU 3251 Being a Hero(最小割+输出割边)
Problem DescriptionYou are the hero who saved your country. As promised, the king will give you some ...
- TZOJ 3315 买火车票(线段树区间最小值)
描述 Byteotian州铁道部决定赶上时代,为此他们引进了城市联网.假设城市联网顺次连接着n 个市从1 到n 编号(起始城市编号为1,终止城市编号为n).每辆火车有m个座位且在任何两个运送更多的乘客 ...
- POJ 1177 Picture(线段树周长并)
描述 A number of rectangular posters, photographs and other pictures of the same shape are pasted on ...
- springmvc+logback项目的日志搭建
一.重写HTMLLayout 两个自定义类:LzhHTMLLayoutBase和LzhHTMLLayout LzhHTMLLayoutBase代码如下: package top.liaozhengha ...
- 关于xshell连接阿里云服务器后报错的问题,git安装失败,找不到git包
1.如果安装git出现这样的错误的,在接下来键入这样一行命令 curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-c ...