<!--按结果嵌套处理--><selectid="getTeacher"resultMap="TeacherStudent">
select s.id sid,s.name sname,t.name tname,t.id tid
from student s, teacher t where s.tid=t.id
and t.id=#{tid};
</select><resultMapid="TeacherStudent"type="Teacher"><resultproperty="id"column="tid"></result><resultproperty="name"column="tname"></result><!-- 复杂的属性,我们需要单独处理 对象:association
集合:collection
集合中的泛型信息,我们用ofType获取
--><collectionproperty="students"ofType="Student"><resultproperty="id"column="sid"></result><resultproperty="name"column="sname"></result><resultproperty="tid"column="tid"></result></collection></resultMap>
按照查询嵌套处理
<!--按照查询嵌套处理--><selectid="getTeacher2"resultMap="TeacherStudent2">
select * from mybatis.teacher where id=#{tid}
</select><resultMapid="TeacherStudent2"type="Teacher"><collectionproperty="students"javaType="ArrayList"ofType="Student"select="getStudentByTeacherId"column="id"></collection></resultMap><selectid="getStudentByTeacherId"resultType="Student">
select * from mybatis.student where tid=#{tid};
</select>
按照结果嵌套处理<!--按结果嵌套处理--> <select id="getTeacher" resultMap="TeacherStudent"> select s.id sid,s.name sname,t.name tname,t.id tid from student s, teacher t where s.tid=t.id and t.id=#{tid}; </select> <resultM