如何通过一个集合过滤另一个集合?
有2套,用户有很多字段,但是必须的就是departmentId,他们还给了我一个id数组用于删除,还有这个那个Strig。如何迭代 oldUser 并仅保留departmentId 位于removeUserById 中的那些用户?下面是我写的流,但它不起作用,所有用户都无一例外地进入 abс 集
Set<User> oldEmploee = userRepository.findAllByDepartmentId(departmentId);
Set<String> newEmploee = command.getEmployees();
Set<User> abc = oldEmploee.stream().filter(e -> !newEmploee.contains(e.getDepartmentId())).collect(Collectors.toSet());
abc.forEach(user -> user.setDepartmentId("3a9b4a8a-9e8c-4b72-b3cd-4e72090c259b"));
userRepository.saveAll(abc);
There are 2 sets, the user has a lot of fields, but the necessary one is the departmentId, they also gave me an id array for deletion, and this and that Strig. How can you iterate over oldUser and leave only those users whose departmentId is in removeUserById? Below is the stream that I wrote But it does not work, all users go to the abс set without exceptions
Set<User> oldEmploee = userRepository.findAllByDepartmentId(departmentId);
Set<String> newEmploee = command.getEmployees();
Set<User> abc = oldEmploee.stream().filter(e -> !newEmploee.contains(e.getDepartmentId())).collect(Collectors.toSet());
abc.forEach(user -> user.setDepartmentId("3a9b4a8a-9e8c-4b72-b3cd-4e72090c259b"));
userRepository.saveAll(abc);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)