DepartmentDao 接口
public interface DepartmentDao {
@Select("select * from t_department")
@Results({
@Result(column="d_id",property="id"),
@Result(column="d_name",property="name"),
@Result(column="d_id",property="employees",
javaType=Set.class,many=@Many(select="getEmployeeById")
)
})
List<Department> getDepartments() throws Exception;
@Select("select * from t_employee where depart_id=#{id}")
@Results({
@Result(column="e_id",property="id"),
@Result(column="e_name",property="name"),
@Result(column="e_sex",property="sex"),
@Result(column="e_age",property="age"),
})
Employee getEmployeeById(int id) throws Exception;
@Select("select * from t_department where d_id=#{id}")
@Results({
@Result(column="d_id",property="id"),
@Result(column="d_name",property="name"),
@Result(column="d_id",property="employees",
javaType=Set.class,many=@Many(select="getEmployeeById")
)
})
Department getDepartmentById(int id) throws Exception;
}
EmployeeDao 接口
public interface EmployeeDao {
@Select("select * from t_employee")
@Results({
@Result(column="e_id",property="id"),
@Result(column="e_name",property="name"),
@Result(column="e_age",property="age"),
@Result(column="e_sex",property="sex"),
@Result(column="depart_id",property="department",
javaType=Department.class,
one=@One(select="getDepartmentById")
)
})
List<Employee> getEmployees() throws Exception;
@Select("select * from t_department where d_id=#{id}")
@Results({
@Result(column="d_id",property="id"),
@Result(column="d_name",property="name")
})
public Department getDepartmentById(int id) throws Exception;
@Select("select * from t_employee where e_id=#{id}")
@Results({
@Result(column="e_id",property="id"),
@Result(column="e_name",property="name"),
@Result(column="e_age",property="age"),
@Result(column="e_sex",property="sex"),
@Result(column="depart_id",property="department",
javaType=Department.class,
one=@One(select="getDepartmentById")
)
})
Employee getEmployeeById(int id) throws Exception;
}