mybatis学习 十五 resultMap标签 一对多

多次查询,非联合查询版本

     <resultMap type="teacher" id="techMap">
          <id column="id" property="id"/>
          <result column="name" property="name"/>
          <collection property="list" column="id" ofType="student"
              select="com.xxx.mapper.StudentMapper.selByTid">
          </collection>
      </resultMap>    

            <select id="selAll" resultMap="techMap">
              select * from teacher
          </select> 

联合查询版本

<resultMap type="teacher" id="mymap1">
    <id column="tid" property="id"/>
    <result column="tname" property="name"/>
    <collection property="list" ofType="student" >
        <id column="sid" property="id"/>
        <result column="sname" property="name"/>
        <result column="age" property="age"/>
        <result column="tid" property="tid"/>
    </collection>
</resultMap>
<select id="selAll1" resultMap="mymap1">
    select t.id tid,t.name tname,s.id sid,s.name  sname,age,tid
   
     from teacher t LEFT JOIN student s on  t.id=s.tid;
   
</select>        

 

posted @ 2018-09-16 19:19  阿瞒123  阅读(315)  评论(0编辑  收藏  举报