日期:2014-05-20 浏览次数:20728 次
Class Company{
int id;
String comName;
List<Dept> depts;
}
Class Dept{
int id;
String deptName;
int comId;
List<Employee> employees;
}
Class Employee{
int id;
String age;
String name;
int deptId;
}
Class EmployeeForShow{
String age;
String name;
String deptName;
}
<resultMap id="EmployeeResult" class="Employee" >
<result column="id" property="id" />
<result column="age" property="age" />
<result column="name" property="name"/>
<result column="deptId" property="deptId"/>
</resultMap>
<resultMap id="DeptResult" class="Dept" >
<result column="id" property="id" />
<result column="deptName" property="deptName" />
<result property="employees" javaType="java.util.List" resultMap="EmployeeResult"/>
</resultMap>
<resultMap id="CompanyResult" class="Company" >
<result column="id" property="id" />
<result column="comName" property="comName" />
<result property="depts" javaType="java.util.List" resultMap="DeptResult"/>
</resultMap>
<resultMap id="ForShow" class="EmployeeForShow">
<result column="age" property="age" />
<result column="name" property="name"/>
<result column="deptname" property="deptname"/>
</resultMap>
<select id="getEmployeesByCompanyId" parameterClass="int" resultMap="ForShow">
select e.name,e.age,d.deptName from company c,dept d,employee e where c.id=d.comId and d.id=e.deptId and c.id=#value#
</select>