连表查询
多对一查询
<select id="findAll2" resultMap="a1">
SELECT s.`id` sid ,s.`name` sname ,t.`name` tname
FROM `student` s ,`teacher` t
WHERE s.`tid`=t.`id`
</select>
<resultMap id="a1" type="pojo.Student">
<result property="id" column="sid"/>
<result property="name" column="sname"/>
<association property="teacher" javaType="pojo.Teacher">
<result property="name" column="tname"/>
</association>
</resultMap>
一对多查询
<select id="getTeacher" resultMap="a2">
SELECT t.name tname,s.name sname FROM teacher t,student s WHERE s.tid=t.id
</select>
<resultMap id="a2" type="pojo.Teacher2">
<result property="name" column="tname"/>
<collection property="student2" ofType="pojo.Student2">
<result property="name" column="sname"/>
</collection>
</resultMap>