zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    MySQL缓存的查询和清除命令使用详解
    Mysql索引学习笔记
    Java使用BufferedImage修改图片内容
    Vue.js学习
    Linux一键安装宝塔控制面板
    SpringAop注解实现日志的存储
    Spring + SpringMVC + Mybatis项目中redis的配置及使用
    Java 常见异常种类
    6.28笔记-servlet3.0注解配置、文件上传、过滤器、监听器
    6.27-JSTL、标签、分页
  • 原文地址:https://www.cnblogs.com/csslcww/p/9912340.html
Copyright © 2011-2022 走看看