10-many2one

多表连接查询

<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>

 

posted @ 2018-11-05 23:26  深沉有点事  阅读(210)  评论(0编辑  收藏  举报