1、多表连接查询(不能使用延迟加载)
<resultMap type="Country" id="countryMapper">
<id column="cid" property="cid"/>
<result column="cname" property="cname" />
<collection property="minister" ofType="Minister">
<id column="mid" property="mid"/>
<result column="mname" property="mname"/>
</collection>
</resultMap>
<select id="selectCountryById" resultMap="countryMapper">
select cid,cname,mid,mname from tb_country,tb_minister
where countryid=cid and cid=#{xxx}
</select>
2、多表单独查询(开发经常使用,可以使用延迟加载)
<select id="selectMinisterByCountryId" resultType="Minister">
select mid,mname from tb_minister where countryid=#{xxx}
</select>
<resultMap type="Country" id="countryMapper">
<id column="cid" property="cid"/>
<result column="cname" property="cname" />
<collection
property="minister"
ofType="Minister"
select="selectMinisterByCountryId"
column="cid"
/>
</resultMap>
<select id="selectCountryById" resultMap="countryMapper">
select cid,cname from tb_country
where cid=#{xxx}
</select>