@Override
public List<DeviceGroupVo> getDeviceGroup() {
//查询全部
List<DeviceGroupVo> deviceGroup = deviceGroupDao.getDeviceGroup();
List<DeviceGroupVo> collect = deviceGroup.stream()
.filter(item -> item.getParentGroupCode().toString().equals("0"))
.map(deviceGroupVo -> {
deviceGroupVo.setChilds(getDeviceGroupChilds(deviceGroupVo,deviceGroup));
return deviceGroupVo;
}).collect(Collectors.toList());
return collect;
}
/***
* Desc: 递归下一级子菜单
* @param root
* @param all
* @return {@link List< DeviceGroupVo>}
* @author sheng jia hao
* @date 2021/3/17 13:35
*/
public List<DeviceGroupVo> getDeviceGroupChilds(DeviceGroupVo root,List<DeviceGroupVo> all) {
List<DeviceGroupVo> collect = all.stream()
.filter(item -> item.getParentGroupCode().equals(root.getGroupCode()))
.map(deviceGroupVo -> {
deviceGroupVo.setChilds(getDeviceGroupChilds(deviceGroupVo, all));
return deviceGroupVo;
}).collect(Collectors.toList());
return collect;
}
java8 lambda表达式 递归查询 属性结构
最新推荐文章于 2025-04-20 16:37:37 发布