频道栏目
首页 > 资讯 > 其他综合 > 正文

mybatis多表关联查询

16-12-10        来源:[db:作者]  
收藏   我要投稿

mybatis多表关联查询:最近才开始接触的mybatis,也没有深入的研究相关文档,只是用到什么就去查什么,就在今天,在写Mapper的时候,突然要用到多表关联查询,瞬间有点小蒙蔽,差点就想着一个表的一个表先查出来,放在各自的model中,可是感觉太烦了,于是就开始折腾了。

<mapper namespace="com.willu.dao.Tb_statyRecordsMapper">
<resultmap id="BaseResultMap" type="com.willu.model.Tb_statyRecords">
<id column="Id" jdbctype="INTEGER" property="id"><br />
<result column="StudentCode" jdbctype="VARCHAR" property="studentcode">
<result column="BuildingName" jdbctype="VARCHAR" property="buildingname">
<result column="RoomNum" jdbctype="INTEGER" property="roomnum">
<result column="BedNum" jdbctype="INTEGER" property="bednum"> </result></result></result></result></id></resultmap>
<br />
<resultmap id="BaseResultMap1" type="com.willu.model.Result.Manager.AccomodationInfoModel">
<id column="Id" jdbctype="INTEGER" property="id">
<result column="CampusName" jdbctype="VARCHAR" property="campusName">
<result column="BuildingName" jdbctype="VARCHAR" property="building">
<result column="RoomNum" jdbctype="INTEGER" property="roomNumber">
<result column="BedNum" jdbctype="INTEGER" property="bedNumber">
<result column="StudentCode" jdbctype="VARCHAR" property="studentCode">
<result column="StudentName" jdbctype="VARCHAR" property="studentName">
<result column="Sex" jdbctype="VARCHAR" property="sex">
<result column="Phone" jdbctype="VARCHAR" property="phone">
<result column="Faculty" jdbctype="VARCHAR" property="faculty">
<result column="Profession" jdbctype="VARCHAR" property="profession">
<result column="Grade" jdbctype="VARCHAR" property="grade">
<result column="ClassNo" jdbctype="VARCHAR" property="classNo">
<result column="AdminsionTime" jdbctype="DATE" property="adminsionTime">
<result column="Xuezhi" jdbctype="INTEGER" property="xuezhi">
<result column="Education" jdbctype="VARCHAR" property="education">
<result column="Membership" jdbctype="VARCHAR" property="membership">
<result column="Nation" jdbctype="VARCHAR" property="nation"> </result></result></result></result></result></result></result></result></result></result></result></result></result></result></result></result></result></id></resultmap>

自己是在逆向工程生成的DAO和Mapper中改的,并没有新建DAO和Mapper,不知道这个想法咋样,反正搞起来了。

首先,多表关联查询,想要的得到的就不仅仅是一个表内的数据了,所以就不可能用原来的model去接收结果集。理应用一个新的model去接收结果集。 顺着这个 思路,去创了一个新的model类。 然后楼主个搞了好久,才知道在Mapper中该怎么使用这个新的model。 下面是楼主搞好的代码
BaseResultMap是表的结果集映射,BaseResultMap1是楼主根据新model建立的。
其中要注意的有:1.column对应的是数据库中对应的属性名
2.property对应的是model对应的属性名

这是新手楼楼今天遇到的,希望能对大家有所帮助。

相关TAG标签
上一篇:Redis源码解析:字典遍历
下一篇:MySQL数据库(三)
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站