Java笔记:sorted()

		// 查询全部部门
		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))

移入语雀里面更加详细


版权声明:本文为weixin_44866272原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。