首页 > 其他 > 详细

one2one

时间:2018-11-06 00:13:32      阅读:226      评论:0      收藏:0      [点我收藏+]

多表连接

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

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

    <!-- 定义结果映射关系 -->
    <resultMap type="Husband" id="husbandMap">
        <id column="hid" property="hid" />
        <result column="hname" property="hname" />
        <association property="wife" javaType="Wife">
            <id column="wid" property="wid" />
            <result column="wname" property="wname" />
        </association>
    </resultMap>

    <select id="selectHusbandById" resultMap="husbandMap">
        select hid,hname,wid,wname
        from husband,wife
        where wid=wifeId and hid=#{xxx}
    </select>

</mapper>

 

多表单独

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

    <!-- 多表单独查询 -->

    <select id="selectWifeByHusband" resultType="Wife">
        select wid,wname from wife where wid=#{jjj}
    </select>

    <!-- 定义结果映射关系 -->
    <resultMap type="Husband" id="husbandMap">
        <id column="hid" property="hid" />
        <result column="hname" property="hname" />
        <association property="wife" 
                     javaType="Wife"
                     select="selectWifeByHusband"
                     column="wifeId"/>
    </resultMap>

    <select id="selectHusbandById" resultMap="husbandMap">
        select hid,hname,wifeId from husband where hid=#{xxx}
    </select>

</mapper>

多表连接2

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

    <!-- 定义结果映射关系 -->
    <resultMap type="Husband" id="husbandMap">
        <id column="hid" property="hid" />
        <result column="hname" property="hname" />
        <association property="wife" javaType="Wife">
            <id column="wid" property="wid" />
            <result column="wname" property="wname" />
        </association>
    </resultMap>

    <select id="selectHusbandById" resultMap="husbandMap">
        select hid,hname,wid,wname
        from husband,wife
        where wid=hid and hid=#{xxx}
    </select>

 

多表单独2

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

    <!-- 多表单独查询 -->

    <select id="selectWifeByHusband" resultType="Wife">
        select wid,wname from wife where wid=#{jjj}
    </select>

    <!-- 定义结果映射关系 -->
    <resultMap type="Husband" id="husbandMap">
        <id column="hid" property="hid" />
        <result column="hname" property="hname" />
        <association property="wife" 
                     javaType="Wife"
                     select="selectWifeByHusband"
                     column="hid"/>
    </resultMap>

    <select id="selectHusbandById" resultMap="husbandMap">
        select hid,hname from husband where hid=#{xxx}
    </select>

</mapper>

 

one2one

原文:https://www.cnblogs.com/csslcww/p/9912340.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!