多对一
<select id="selectAllStudent" resultMap="StudentTeacher">
select s.id as sid, as sname, as tname, as tid from student as s,teacher as t
where s.tid=
</select>
<resultMap id="StudentTeacher" type="Student">
<result property="id" column="sid"/>
<result property="name" column="sname"/>
<association property="teacher" javaType="Teacher">
<result property="id" column="tid"></result>
<result property="name" column="tname"></result>
</association>
</resultMap>
javaType 参数是实体类的类型,property实体类变量的名。
一对多
<select id="getTeacher" resultMap="TeacherStudent">
select s.id as sid, as sname, as tname, as tid
from student as s,teacher as t
where =s.tid
and =#{tid}
</select>
<resultMap id="TeacherStudent" type="Teacher">
<result property="id" column="tid"/>
<result property="name" column="tname"/>
<collection property="students" ofType="Student">
<result property="id" column="sid"></result>
<result property="name" column="sname"></result>
<result property="tid" column="tid"></result>
</collection>
</resultMap>