查询没有签到用户列表
时间: 2023-07-06 17:10:51 浏览: 39
假设有一个签到记录列表,每个签到记录都有一个用户id属性,可以根据这个属性来查询没有签到的用户列表。假设用户列表存在一个List<User>对象中,签到记录列表存在一个List<SignRecord>对象中,可以按照以下步骤来查询没有签到的用户列表:
1. 先获取所有已签到的用户id列表,可以使用Stream API的map方法和collect方法来实现:
```
List<Integer> signedUserIds = signRecordList.stream()
.map(SignRecord::getUserId)
.collect(Collectors.toList());
```
2. 然后将用户列表中未签到的用户过滤出来,可以使用Stream API的filter方法来实现:
```
List<User> unsignedUsers = userList.stream()
.filter(user -> !signedUserIds.contains(user.getId()))
.collect(Collectors.toList());
```
3. 最后得到的unsignedUsers就是没有签到的用户列表。
完整代码如下:
```
List<Integer> signedUserIds = signRecordList.stream()
.map(SignRecord::getUserId)
.collect(Collectors.toList());
List<User> unsignedUsers = userList.stream()
.filter(user -> !signedUserIds.contains(user.getId()))
.collect(Collectors.toList());
```
需要注意的是,这里的User和SignRecord类需要根据实际情况进行替换。