<selectid="getTeacher2"resultMap="getTeacherStudent2"> select id as tid,name as tname from teacher where id = #{tid}; </select> <resultMapid="getTeacherStudent2"type="Teacher"> <resultproperty="id"column="tid"/> <resultproperty="name"column="tname"/> <collectionproperty="students"javaType="ArrayList"ofType="Student"column="tid"select="getStudentByTeacherId"/> </resultMap>
<selectid="getStudentByTeacherId"resultType="Student"> select * from students where tid = #{tid} </select>