<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.mapper.TeacherMapper"><selectid="setSelect"resultMap="teachermap">
/*不用别名,下面基本用不了,识别不了字段是那个*/
select t.id,t.name,s.id sid,s.name sname,s.teaid steaid
from teacher t
join student s
on t.id=s.teaid
where t.id=#{id}
</select><resultMapid="teachermap"type="teacher"><!--不知道为什么,一定要加上这两个,不加就会错误--><resultproperty="id"column="id"/><resultproperty="name"column="name"/><!--获取多个student数据,使用collection,ofType是集合的返回类型与javatype一样--><collectionproperty="student"ofType="student"><resultproperty="name"column="sname"/><resultproperty="id"column="sid"/><resultproperty="teaid"column="steaid"/></collection></resultMap></mapper>