日期:2014-05-20  浏览次数:20682 次

关于ibatis多表关联查询的配置文件问题,求教!
最近因为工作需要在学习Ibaits框架,现在有个需求,搞不定,请大家帮帮忙!
有4个类  Company,Dept,Employee,EmployeeForShow
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;
}
  
前三个类的属性和数据库表结构相同,现在的需求是我想通过company的id找出所有的employmee及所属的部门名称即EmployeeForShow对象
sql语句: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="参数";
以下是我写的xml配置文件
<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>

这个配置文件有问题,请高手指点下如何配置
------解决方案--------------------
给你推荐一篇文章,里面有这个问题的解决方案
------解决方案--------------------
javaeye的一篇文章,不错。http://cuishen.iteye.com/blog/544207应该是和解决这个问题。