81,092
社区成员
发帖
与我相关
我的任务
分享
public class School {
private String id;
private String name;
private List<Teacher> teacherList = new ArrayList<Teacher>();
private List<Student> studentList = new ArrayList<Student>();
public String getId() {
return id;
}
public void setId(String _id) {
id = _id;
}
public String getName() {
return name;
}
public void setName(String _name) {
name = _name;
}
public List<Teacher> getTeacherList() {
return teacherList;
}
public void setTeacherList(List<Teacher> _teacherList) {
teacherList = _teacherList;
}
public List<Student> getStudentList() {
return studentList;
}
public void setStudentList(List<Student> _studentList) {
studentList = _studentList;
}
}
<?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="com.bambloo.mybatis.test.SchoolMapper">
<resultMap type="Student" id="studentMap">
<id property="id" column="eid" />
<result property="name" column="ename" />
</resultMap>
<resultMap type="Teacher" id="teacherMap">
<id property="id" column="eid" />
<result property="name" column="ename" />
</resultMap>
<resultMap type="School" id="schoolMap">
<id property="id" column="sid" />
<result property="name" column="sname" />
<discriminator javaType="String" column="etype">
<case value="1" resultMap="studentMap">
<collection property="studentList"/>
</case>
</discriminator>
</resultMap>
<select id="getSchool" resultType="School" resultMap="schoolMap">
select
s.id sid,s.name sname,e.id eid,e.type etype,e.name ename
from school s
left
join entity e on e.s_id=s.id
where s.id=#{id}
</select>
</mapper>