<mappernamespace="com.kuang.dao.TeacherMapper"><selectid="getTest"resultType="Teacher">
select * from teacher
</select><!--获取指定老师,及老师对应的所有学生--><!-- 思路:按结果嵌套处理
1. 从学生表和老师表中查出学生id,学生姓名,老师姓名
2. 对查询出来的操作做结果集映射
1. 集合的话,使用collection! JavaType和ofType都是用来指定对象类型的 JavaType是用来指定pojo中属性的类型
ofType指定的是映射到list集合属性中pojo的类型。
--><selectid="getTeacher"resultMap="TeacherStudent">
select t.id tid,t.name tname,s.id sid,s.name sname from teacher t ,student s
where t.id = s.tid and t.id = #{id}
</select><resultMapid="TeacherStudent"type="Teacher"><resultproperty="name"column="tname"/><collectionproperty="students"ofType="Student"><resultproperty="id"column="sid"/><resultproperty="name"column="sname"/><resultproperty="tid"column="tid"/></collection></resultMap><!--按查询嵌套处理--><selectid="getTeacher2"resultMap="TeacherStudent2">
select * from teacher where id = #{id}
</select><resultMapid="TeacherStudent2"type="Teacher"><!--column是一对多的外键 , 写的是一的主键的列名--><collectionproperty="students"javaType="ArrayList"ofType="Student"column="id"select="getStudentByTeacher"></collection></resultMap><selectid="getStudentByTeacher"resultType="Student">
select * from student where tid = #{id}
</select></mapper>