mybatis遇到的一个问题
public class Employee
{
private int id;
private String name;
private int age;
private int gender;
//get、set方法。。。。
}
public class Department
{
private int id;
private String name;
private int accounts;
private List<Employee> employees;
//get、set方法。。。。
}
===============语句映射文件================
<mapper namespace="inter.InterOperation">
<select id="getDepartment" resultMap="resultDepartment" >
select d.did,
d.name,
d.accounts,
e.eid,
e.age,
e.name1,
e.gender
from
department d,employee e
where e.employee_department_id=d.did and d.did=#{id}
</select>
<resultMap type="Department" id="resultDepartment">
<id property="did" column="id"/>
<result property="name" column="name"/>
<result property="accounts" column="accounts"/>
<collection property="employees" ofType="Employee">
<id property="eid" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
<result property="gender" column="gender"/>
</collection>
</resultMap>
</mapper>
=============测试代码=====================
InterOperation interOperation = sqlSession
.getMapper(InterOperation.class);
Department d = interOperation.getDepartment(1);
System.out.println("d.getName:"+d.getName());
assertEquals("dep1", d.getName());
System.out.println(d.getEmployees().size());
for(Employee e:d.getEmployees())
System.out.println("e.getName:"+e.getName());
//在这里打印出的本应该是Employee所对应的name,发现打印出的都是Department的name
发现解决办法是把数据库里的Employee的name变成name1
mybatis这么锉???还是我用的不对??
还有,各位有好的mybatis的教程推荐么,官方的教程好像太简略了
}