Java笔记:sorted()

该博客探讨了如何在Java中查询并管理所有部门及其数据权限。通过使用`deptMapper`查询全部和权限内部门,然后利用Stream进行过滤和排序,创建了一个展示有无权限标识的部门树结构。内容涉及到列表排序、数据权限判断以及转换为TreeNode对象的过程。
摘要由CSDN通过智能技术生成
		// 查询全部部门
		List<SysDept> deptAllList = deptMapper.selectList(Wrappers.emptyWrapper());
		// 查询数据权限内部门
		List<Integer> deptOwnIdList = deptMapper.selectListByScope(Wrappers.emptyWrapper(), new DataScope()).stream()
				.map(SysDept::getDeptId).collect(Collectors.toList());

		// 权限内部门
		List<TreeNode<Integer>> collect = deptAllList.stream()
				.filter(dept -> dept.getDeptId().intValue() != dept.getParentId())
                 //排序
				.sorted(Comparator.comparingInt(SysDept::getSort)).map(dept -> {
					TreeNode<Integer> treeNode = new TreeNode();
					treeNode.setId(dept.getDeptId());
					treeNode.setParentId(dept.getParentId());
					treeNode.setName(dept.getName());
					// 有权限不返回标识
					treeNode.setExtra(MapUtil.of("isLock", !deptOwnIdList.contains(dept.getDeptId())));
					return treeNode;
				}).collect(Collectors.toList());

自然序排序一个list

list.stream().sorted() 

使用Comparator 来排序一个list

sorted(Comparator.comparingInt(SysDept::getSort))

移入语雀里面更加详细

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值