编程日记 后端tags过滤器
这样查出来了所有的信息,不对
检查是这个地方有问题
改掉
@Override
public List<User> searchUsersByTags(List<String> tagNameList) {
//1.先查询所有用户
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
List<User> userList = userMapper.selectList(queryWrapper);
Gson gson = new Gson();
//2.在内存中判断是否包含所要求的标签
return userList.stream().filter(user -> {
String tagStr = user.getTags();
Set<String> tempTagNameSet = gson.fromJson(tagStr, new TypeToken<Set<String>>(){}.getType());
//Optional.ofNullable可以少写一层if判断(如果查询结果为空)
tempTagNameSet= Optional.ofNullable(tempTagNameSet).orElse(new HashSet<>());
for (String tagName : tagNameList) {
if (!tempTagNameSet.contains(tagName)) {
return false;
}
}
return true;
}).map(this::getSafetyUser).collect(Collectors.toList());
/* */
ok,成功了
标签:return,tags,编程,List,tempTagNameSet,过滤器,new From: https://www.cnblogs.com/vastjoy/p/18415721