亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

mybatis 一對(duì)一、一對(duì)多和多對(duì)多查詢實(shí)例代碼

 更新時(shí)間:2018年06月08日 10:05:07   作者:程序yuan  
這篇文章主要介紹了mybatis 一對(duì)一、一對(duì)多和多對(duì)多查詢的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

關(guān)鍵字:association 一對(duì)一映射(一個(gè)班級(jí)只有一個(gè)班主任)

  <select id="getClass" parameterType="int" resultMap="ClassesResultMap">  
    select * from class c,teacher t where c.teacher_id=t.t_id and c.c_id=#{id}  
  </select>  
  <resultMap type="com.lcb.user.Classes" id="ClassesResultMap">  
    <id property="id" column="c_id"/>  
    <result property="name" column="c_name"/>  
    <association property="teacher" javaType="com.lcb.user.Teacher">  
      <id property="id" column="t_id"/>  
      <result property="name" column="t_name"/>  
    </association>  
  </resultMap>  

關(guān)鍵字:collection 一對(duì)多映射(一個(gè)老師有多個(gè)學(xué)生)

<resultMap type="Teacher" id="teacherMaps">  
    <id column="id" property="id"/>  
    <result column="name" property="name"/>  
    <result column="class_name" property="className"/>  
    <collection property="students" ofType="Student" select="getStudents" column="id">  
    </collection>  
  </resultMap>  
  <!-- 查詢所有的老師級(jí)各自的所有學(xué)生 -->  
  <select id="getAllTeacher" parameterType="Teacher" resultMap="teacherMaps">  
    SELECT  
      t.id,  
      t.NAME,  
      t.class_name  
    FROM  
      teacher t  
  </select>  
  <select id="getStudents" parameterType="int" resultType="Student">  
    select   
      s.id,  
      s. NAME,  
      s.class_name as className  
    from student s  
    where teacher_id = #{id}  
  </select> 

    關(guān)鍵字:association 多對(duì)一映射(多個(gè)人屬于一個(gè)國(guó)家)

             多對(duì)一相當(dāng)于一對(duì)多,也可以使用collection

<select id="selectCountry" resultType="Country">  
  select cid,cname from country where cid=#{ooo}  
</select>  
<resultMap type="People" id="peopleMapper2">  
  <id column="pid" property="pid"/>  
  <result column="pname" property="pname"/>  
  <association property="country"   
         javaType="Country"  
         select="selectCountry"  
         column="countryId" />  
</resultMap>  
  <select id="selectById2" resultMap="peopleMapper2">  
  select pid,pname,countryId from people where pid = #{xxx}  
</select>  

總結(jié)

以上所述是小編給大家介紹的mybatis 一對(duì)一、一對(duì)多和多對(duì)多查詢,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論