service层
/**
* 获取所有部门
* @return
*/
public List<Department> getAllDepartments() {
return departmentMapper.getAllDepartments();
}
mapper层
/**
* 查询所有部门
* @return
*/
("select * from t_department where parent_id = 0")
(id = "departmentMap",value = {
(property = "id",column = "id"),
(property = "name",column = "name"),
(property = "parentId",column = "parent_id"),
(property = "depPath",column = "dep_path"),
(property = "enabled",column = "enabled"),
(property = "isParent",column = "is_parent"),
(property = "children",column = "id",many = (select = "getAllDepartmentsId")),//这里表示一对多 一里面包含多
})
List<Department> getAllDepartments();
("select * from t_department where parent_id = #{parent_id}")
("departmentMap")
List<Department> getAllDepartmentsId();
children: 它是在实体类定义的字段 private List children;
id = "departmentMap": 通过注解@Results来指定对应关系 指定@ResultMap("departmentMap")
column指定数据库字段的名称,property指定实体类属性的名称,jdbcType数据库字段类型,@Result里的id值为true表明主键,默认false