public class Teacher {
private String id;
private String name;
}
public class Classes {
private String id;
private String name;
private Teacher teacher;
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.mybatis.example.classesMapper">
<select id="getClasses" resultMap="getClassesMap">
select * from classes c,teacher t where c.teacher_id=t.t_id and c.c_id=#{id}
</select>
<resultMap type="Classes" id="getClassesMap">
<id property="id" column="c_id"/>
<result propery="name" column="c_name"/>
<!-- 属性名是teacher ,类型是Teacher-->
<association property="teacher" javaType="Teacher">
<!-- 设置Teacher的属性 -->
<id property="id" column="t_id"/>
<result propery="name" column="t_name"/>
</association>
</resultMap>
</mapper>