1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE mapper 3 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 4 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 5 <mapper namespace="com.mapper.ClazzMapper"> 6 <!--开启二级缓存--> 7 <cache/> 8 <resultMap id="classMap" type="Clazz"> 9 <id property="id" column="cid"/> 10 <result property="name" column="cname"/> 11 <result property="room" column="room"/> 12 <collection property="stu" javaType="list" ofType="Student"> 13 <id property="id" column="sid"/> 14 <result property="name" column="sname"/> 15 <result property="age" column="age"/> 16 <result property="gender" column="gender"/> 17 <result property="cid" column="cid"/> 18 </collection> 19 </resultMap> 20 <select id="selAll" resultMap="classMap"> 21 select c.id cid, c.name cname, c.room, s.id sid, s.name sname, s.age, s.gender 22 from t_student s 23 right join t_class c 24 on s.cid=c.id 25 </select> 26 27 </mapper>