<selectid="findById"resultMap="student_Class">
select * from stu3 WHERE sid=#{id}
select><resultMapid="student_Class"type="stu3"><idproperty="sid"column="sid">id><collectionproperty="class3s"column="sid"select="getClass">collection>resultMap><selectid="getClass"resultType="Class3">
SELECT * FROM (select cid FROM temp01 WHERE sid=#{sid}) a
INNER JOIN class3 c3 ON c3.cid=a.cid
select>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
4 findByCid方法及其xml中对应的标签内容
4.1 findByCid(方法) 根据学生id找到他所对应的所有课程信息
Class3findByCid(String id);
1
4.2 xml中对应的标签内容
<selectid="findByCid"resultMap="class_stu">
select * from class3 WHERE cid=#{id}
select><resultMapid="class_stu"type="Class3"><idproperty="cid"column="cid">id><collectionproperty="stu3s"column="cid"select="getStu">collection>resultMap><selectid="getStu"resultType="Stu3">
SELECT * FROM (SELECT sid FROM temp01 WHERE cid=#{cid}) t INNER JOIN
stu3 s ON t.sid=s.sid
select>
DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="mapper.StudentToClass"><selectid="findById"resultMap="student_Class">
select * from stu3 WHERE sid=#{id}
select><resultMapid="student_Class"type="stu3"><idproperty="sid"column="sid">id><collectionproperty="class3s"column="sid"select="getClass">collection>resultMap><selectid="getClass"resultType="Class3">
SELECT * FROM (select cid FROM temp01 WHERE sid=#{sid}) a
INNER JOIN class3 c3 ON c3.cid=a.cid
select><selectid="findByCid"resultMap="class_stu">
select * from class3 WHERE cid=#{id}
select><resultMapid="class_stu"type="Class3"><idproperty="cid"column="cid">id><collectionproperty="stu3s"column="cid"select="getStu">collection>resultMap><selectid="getStu"resultType="Stu3">
SELECT * FROM (SELECT sid FROM temp01 WHERE cid=#{cid}) t INNER JOIN
stu3 s ON t.sid=s.sid
select>mapper>