<mapper namespace="com.abc.dao.IMinisterDao">
<!-- 多表连接查询 -->
<!-- 定义结果映射关系 -->
<resultMap type="Minister" id="ministerMap">
<id column="mid" property="mid" />
<result column="mname" property="mname" />
<association property="country" javaType="Country">
<id column="cid" property="cid" />
<result column="cname" property="cname" />
</association>
</resultMap>
<select id="selectMinisterById" resultMap="ministerMap">
select mid,mname,cid,cname
from minister, country
where countryId=cid and mid=#{xxx}
</select>
</mapper>
<mapper namespace="com.abc.dao.IMinisterDao">
<!-- 多表单独查询 -->
<select id="selectCountryByMinister" resultType="Country">
select cid,cname from country where cid=#{jjj}
</select>
<!-- 定义结果映射关系 -->
<resultMap type="Minister" id="ministerMap">
<id column="mid" property="mid" />
<result column="mname" property="mname" />
<association property="country"
javaType="Country"
select="selectCountryByMinister"
column="countryId"/>
</resultMap>
<select id="selectMinisterById" resultMap="ministerMap">
select mid,mname,countryId from minister where mid=#{xxx}
</select>
</mapper>