1、多表连接查询(不延迟加载)
<resultMap type="Minister" id="ministerMapper">
<id column="mid" property="mid" />
<association property="country" javaType="Country">
<id column="cid" property="cid" />
<result column="cnmae" property="cname"/>
</association>
</resultMap>
<select id="selectMinisterById" resultMap="ministerMapper">
select mid,mname,cid,cname from tb_country,tb_minister
where countryid = cid and mid=#{xxx}
2、多表单独查询(常用,可以延迟加载)
<select id="selectCountryById" resultType="Country">
select cid,cname from tb_country where cid=#{xxx}
</select>
<resultMap type="Minister" id="ministerMapper">
<id column="mid" property="mid" />
<association
property="country"
javaType="Country"
select="selectCountryById"
column="countryid"
/>
</resultMap>
<select id="selectMinisterById" resultMap="ministerMapper">
select mid,mname,countryid
from tb_minister
where mid=#{xxx}
</select>