码迷,mamicode.com
首页 > 其他好文 > 详细

08-one2many

时间:2018-11-06 00:51:26      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:span   collect   sel   oftype   dtd   man   bsp   连接查询   nbsp   

    <!-- 多表连接查询 -->

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.abc.dao.ICountryDao"> <!-- 多表连接查询 --> <!-- 定义结果映射关系 --> <resultMap type="Country" id="countryMap"> <id column="cid" property="cid"/> <result column="cname" property="cname"/> <!-- ofType解释为element of type ,元素类型 --> <collection property="ministers" ofType="Minister"> <id column="mid" property="mid"/> <result column="mname" property="mname"/> </collection> </resultMap> <select id="selectCountryById" resultMap="countryMap"> select cid,cname,mid,mname from country,minister where cid=countryId and cid=#{xxx} </select> </mapper>

 多表单独查询、

<mapper namespace="com.abc.dao.ICountryDao">

    <!-- 多表单独查询 -->
    
    <select id="selectMinisterByCountry" resultType="Minister">
        select mid,mname from minister where countryId=#{ooo}
    </select>

    <!-- 定义结果映射关系 -->
    <resultMap type="Country" id="countryMap">
        <id column="cid" property="cid"/>
        <result column="cname" property="cname"/>
        <!-- ofType解释为element of type ,元素类型 -->
        <collection property="ministers" 
                    ofType="Minister"
                    select="selectMinisterByCountry"
                    column="cid"/>
    </resultMap>

    <select id="selectCountryById" resultMap="countryMap">
        select cid,cname from country where cid=#{xxx}
    </select>

</mapper>

 

08-one2many

标签:span   collect   sel   oftype   dtd   man   bsp   连接查询   nbsp   

原文地址:https://www.cnblogs.com/csslcww/p/9912298.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!