2018-11-13
生成一棵树
如何删除父子节点
@Override
@Transactional(rollbackFor = Exception.class)
public boolean deleteAllById(String depid) {
try{
// 得到对象
FgdjDepartment fgdjDepartment = this.selectById(depid);
// 判断是否父节点
if("1".equals(fgdjDepartment.getNotetype())){
// 父节点,查询出所有的子进行删除
Map<String,String> map = new HashMap<>();
map.put("pcode",fgdjDepartment.getCode());
// 调用方法,查询出所有的子节点
List<FgdjDepartment> list = this.listByPcode(map);
// 循环删除节点
for(FgdjDepartment fgdjDepartment1 : list){
this.deleteAllById(fgdjDepartment1.getDepid());
}
// 再把自己删除了
this.deleteById(depid);
}else {
// 非父节点
this.deleteById(depid);
}
}catch (Exception e){
e.printStackTrace();
return false;
}
return true;
}