根据父级id查询父级下的所有子级(递归算法)

根据父级id查询父级下的所有子级(递归算法)

一、问题:
这里的递归主要用来做,根据父级id查询父级下的所有子级,返回list集合,并放到分页中,分页使用的是,mybatis-plus的插件。

①递归代码

public void getRoleIdChildren(List<AuthRole> roleList,List<AuthRole> resultList,AuthRole role){
        for(AuthRole roleItem : roleList) {
            if(roleItem.getPid().equals(role.getId())) {
                resultList.add(roleItem);
                getRoleIdChildren(roleList,resultList,roleItem);
            }
        }
    }

② 使用
resultList要new在外面,到时候给我们的分页赋值

List<AuthRole> resultList=new ArrayList<>();
if (StringUtils.hasText(data.getId())) {
                AuthRole role = this.getById(data.getId());
                resultList.add(role);
                getRoleIdChildren(this.list(), resultList,role);
            }

③放入到分页中

Page<AuthRole> pageDate = this.baseMapper.selectPage(page, queryWrapper);
		if (data.getId()!=null && data.getId()!=""){
			pageDate.setRecords(roleList);
		}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值