<association>用于关联一个对象
- property: 指定要关联的属性名
- select: 设定要继续引用的查询, namespace+id
- column: 查询时需要传递的列
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.StudentMapper"> 6 <resultMap id="sMap" type="student"> 7 <id property="id" column="sid"/> 8 <result property="name" column="sname"/> 9 <result property="age" column="age"/> 10 <result property="gender" column="gender"/> 11 <result property="cid" column="cid"/> 12 <association property="clazz" javaType="clazz"> 13 <id property="id" column="cid"/> 14 <result property="name" column="cname"/> 15 <result property="room" column="room"/> 16 </association> 17 </resultMap> 18 <select id="selAll" resultMap="sMap"> 19 SELECT 20 s.id sid,s.name sname,s.age,s.gender,c.id cid,c.name cname,c.room 21 from t_student s 22 LEFT JOIN t_class c 23 on s.cid = c.id; 24 </select> 25 </mapper>