refactor: 分页查询
通过数据库进行分页查询而非查询全部然后分页
This commit is contained in:
@@ -279,21 +279,20 @@ public class ArticleServiceImpl implements ArticleService {
|
||||
*/
|
||||
@Override
|
||||
public PageData<ArticleModel> adminArticles(int count, int page, Boolean deleted) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<Article> articleList = articleMapper.findAll();
|
||||
|
||||
PageData<ArticleModel> pageData = new PageData<>(null, 0, count, page);
|
||||
PageData<ArticleModel> pageData = new PageData<>(new PageInfo<>(articleList));
|
||||
|
||||
List<Article> collect;
|
||||
if (deleted != null) {
|
||||
collect = articleList.stream().filter(article -> article.isDeleted() == deleted).collect(Collectors.toList());
|
||||
} else {
|
||||
collect = articleList;
|
||||
}
|
||||
pageData.setTotal(collect.size());
|
||||
List<ArticleModel> articleModels = collect.stream()
|
||||
.peek(article -> article.setMdContent(null))
|
||||
.map(ModalTrans::article)
|
||||
.skip((page - 1) * count)
|
||||
.limit(count)
|
||||
.collect(Collectors.toList());
|
||||
pageData.setList(articleModels);
|
||||
|
||||
|
||||
@@ -181,9 +181,36 @@
|
||||
|
||||
|
||||
<select id="findAll" resultMap="articleViewResultMap">
|
||||
select *
|
||||
from articleView
|
||||
order by articleId desc
|
||||
select article.a_id as articleId,
|
||||
article.a_title as title,
|
||||
article.a_summary as summary,
|
||||
article.a_md_content as mdContent,
|
||||
article.a_url as url,
|
||||
article.a_is_original as isOriginal,
|
||||
article.a_reading_number as readingCount,
|
||||
article.a_like as likeCount,
|
||||
article.a_dislike as dislikeCount,
|
||||
article.a_publish_date as publishDate,
|
||||
article.a_update_date as updateDate,
|
||||
article.a_is_open as isOpen,
|
||||
category.t_id as categoryId,
|
||||
category.t_name as categoryName,
|
||||
user.u_id as authorId,
|
||||
user.u_email as userEmail,
|
||||
user.u_avatar as userAvatar,
|
||||
user.u_display_name as userDisplayName,
|
||||
article.is_delete as isDelete
|
||||
from article,
|
||||
tag_category as category,
|
||||
article_tag,
|
||||
user
|
||||
where article.is_delete = false
|
||||
and article.a_id = article_tag.a_id
|
||||
and article.a_category_id = category.t_id
|
||||
and category.is_category = true
|
||||
and article.a_author_id = user.u_id
|
||||
group by article.a_id
|
||||
order by article.a_id desc
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user