Commit d59d9d2c by 段启岩

提高listByIds时代码的稳定性

parent f597bc35
......@@ -13,6 +13,7 @@ import cn.meteor.beyondclouds.modules.tag.service.ITagService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.HashSet;
import java.util.Iterator;
......@@ -77,10 +78,10 @@ public class QuestionTagServiceImpl extends ServiceImpl<QuestionTagMapper, Quest
.collect(Collectors.toList());
// 3.根据tagIds查询出标签并返回
if (tagIds.size() > 0) {
return tagService.listByIds(tagIds);
if (CollectionUtils.isEmpty(tagIds)) {
return List.of();
} else {
return null;
return tagService.listByIds(tagIds);
}
}
}
......@@ -15,6 +15,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.stream.Collectors;
......@@ -112,7 +113,12 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
.collect(Collectors.toList());
// 3. 通过用户id批量查询用户
List<Topic> topics = listByIds(topicIds);
List<Topic> topics;
if (CollectionUtils.isEmpty(topicIds)) {
topics = List.of();
} else {
topics = listByIds(topicIds);
}
// 5.构造分页结果
IPage<Topic> userPage = new Page<>();
......@@ -143,7 +149,12 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
.collect(Collectors.toList());
// 3. 通过用户id批量查询用户
List<User> followers = userService.listByIds(followerIds);
List<User> followers;
if (CollectionUtils.isEmpty(followerIds)) {
followers = List.of();
} else {
followers = userService.listByIds(followerIds);
}
// 4.去除敏感信息
followers.stream()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment