• one2one


    多表连接

    <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>
  • 相关阅读:
    FastDFS源代码分析之tracker协议分析
    uva 11396Claw Decomposotion(二分图判定)
    Ising模型(伊辛模型)
    开发RESTful WebService
    HDU 4951 Multiplication table 阅读题
    【Quick-COCOS2D-X 3.3 怎样绑定自己定义类至Lua之三】动手绑定自己定义类至Lua
    as3文本框的动态拖拽和编辑
    cocos2d-x3.0rc 版 设置模拟器窗体大小
    chromium for android v34 2dcanvas硬件渲染实现分析
    唐季礼_百度百科
  • 原文地址:https://www.cnblogs.com/csslcww/p/9912340.html
Copyright © 2020-2023  润新知