关联查询
一对一(association)
a.业务扩展类
核心:用resultType指定类的属性 包含 多表查询的所有字段
b.resultMap
i.通过 属性成员 将2个类建立起联系
2.
<resultMap id="Student_card_map" type="Student">
<!--分为主键id和非主键result-->
<id property="stuNo" column="stuno"/>
<result property="stuName" column="stuname"/>
<result property="stuAge" column="stuage"/>
<result property="graName" column="graname"/>
<result property="stuSex" column="stusex" javaType="boolean" jdbcType="INTEGER"/>
<result property="address.homeAddress" column="homeaddress"/>
<result property="address.schoolAddress" column="schooladdress"/>
<!-- 一对一-->
<association property="card" javaType="StudentCard">
<id property="cardId" column="cardid"/>
<result property="cardInfo" column="cardInfo"/>
</association>
</resultMap>
一对多(collection)
表:student studentclass (关联:classid)
类:student studentClass (关联:List students )
<resultMap id="studentClass" type="StudentClass">
<id property="classId" column="classid"/>
<result property="className" column="classname"/>
<collection property="students" ofType="student">
<id property="stuNo" column="stuno"/>
<result property="stuName" column="stuname"/>
<result property="stuAge" column="stuage"/>
</collection>
</resultMap>
一对多
(MyBatis:多对一,多对多的本质就是 一对多的变化)