zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    11.个别程序题
    常见设计模式部分
    框架部分综合
    mybatis部分
    spring部分
    hibernate部分
    struts2部分
    10.java反射和类加载机制
    9.垃圾回收机制和JVM
    oracle部分
  • 原文地址:https://www.cnblogs.com/csslcww/p/9912318.html
Copyright © 2011-2022 走看看