<!--    结果嵌套查询-->
<resultMap id="TeacherStudent" type="Teacher">
<result column="tid" property="id"/>
<result column="tname" property="name"/>
<collection property="students" ofType="Student" column="id">
<result column="sid" property="id"/>
<result column="sname" property="name"/>
<result column="tid" property="tid"/>
</collection>
</resultMap>

<select id="getTeacher" resultMap="TeacherStudent">
select s.id sid, s.name sname, t.id tid, t.name tname from student s, teacher t where s.tid = t.id and t.id = #{tid}

</select>

<!--=============================================================-->

<!-- 按照查询嵌套处理 -->
<resultMap id="TeacherStudent2" type="Teacher">
<collection property="students" javaType="ArrayList" ofType="Student" select="getStudent" column="id"/>
</resultMap>

<select id="getTeacher2" resultMap="TeacherStudent2">
select * from teacher where id = #{tid}
</select>
<select id="getStudent" resultType="Student">
select * from student where tid = #{tid}
</select>
posted on 2022-03-07 22:39  vennkat  阅读(60)  评论(0)    收藏  举报