递归树:获取父目录下的所有子目录

目录结构图:

实体结构:

private Long dirId;
private Long dirParentId;

需求背景:

我需要点击父级目录时查询所有该目录的数据+所有该目录下的所有子目录的数据(子目录有无穷多层)

调用方:

List zmgrDataColumnDirList = Lists.newArrayList();
List dirIds = dataColumnService.selectByParentDirId(zmgrDataColumnDirList, dirId);
List dirIdList = dirIds.stream().map(ZmgrDataColumnDir::getColumnDirId).collect(Collectors.toList());

递归——获取所有该父目录下的所有目录:

    /*** 递归——获取所有该父目录下的所有目录* @param dirId* @return*/public List selectByParentDirId(List zmgrDataColumnDirList, Long dirId) {ZmgrDataColumnDir zmgrDataColumnDir = new ZmgrDataColumnDir();zmgrDataColumnDir.setColumnDirId(dirId);zmgrDataColumnDirList.add(zmgrDataColumnDir);ZmgrDataColumnDirExample zmgrDataColumnDirExample = new ZmgrDataColumnDirExample();zmgrDataColumnDirExample.createCriteria().andDirParentIdEqualTo(dirId);List dirParentIdList = zmgrDataColumnDirMapper.selectByExample(zmgrDataColumnDirExample);for(ZmgrDataColumnDir type : dirParentIdList) {// 递归selectByParentDirId(zmgrDataColumnDirList, type.getColumnDirId());}return zmgrDataColumnDirList;}

 

测试:

(1)表目录 说明:父目录id是3101,他包括他的的所有子目录是3101、3103、3104、2105四个

(2) 代码debug

 

good !

 

 


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部