app端文章列表展示

一、表结构分析

文章信息表、文章配置表、文章内容表

文章信息表:文章ID、图片、布局、作者信息等

文章配置表:是否可转发、评论、删除等

文章内容表:文章内容

其中文章配置表和文章内容表都存在文章ID字段,即与文章信息表为1对1关系

question:为什么文章表要拆分成多个表?

垂直分表:将一个表的字段分散到多个表中,每个表存储其中一部分字段。

优势:

  1. 减少IO争抢,减少锁表的几率,查看文章概述与文章详情互不影响

  2. 充分发挥高频数据的操作效率,对文章概述数据操作的高效率不会被操作文章详情数据的低效率所拖累。

拆分规则:

  1、把不常用的字段单独放在一张表

  2、把text,blob等大字段拆分出来单独放在一张表

  3、经常组合查询的字段单独放在一张表中

 

 

二、实现思路

1、在默认频道展示10条文章信息

2、可以切换频道查看不同种类文章

3、当用户下拉可以加载最新的文章(分页)本页文章列表中发布时间为最大的时间为依据

4、当用户上拉可以加载更多的文章信息(按照发布时间)本页文章列表中发布时间最小的时间为依据

5、如果是当前频道的首页,前端传递默认参数: maxBehotTime:0(毫秒) minBehotTime:20000000000000(毫秒) 2063年【默认加载更多】

复制代码
package com.heima.article.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleMapper;
import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
@Slf4j
public class ApArticleServiceImpl extends ServiceImpl<ApArticleMapper, ApArticle> implements ApArticleService {

    @Autowired
    private ApArticleMapper articleMapper;

    private final static short MAX_PAGE_SIZE = 50;

    /**
     * 加载文章列表
     * @param dto
     * @param type  1:加载更多    2:加载最新
     * @return
     */
    @Override
    public ResponseResult load(ArticleHomeDto dto, Short type) {
        //1、校验参数
        //分页条数的校验
        Integer size = dto.getSize();
        if(size == null || size == 0){
            size = 10;
        }
        //分页的值不超过50
        size = Math.min(size, MAX_PAGE_SIZE);
        dto.setSize(size);

        //type校验
        if(!type.equals(ArticleConstants.LOADTYPE_LOAD_MORE) && !type.equals(ArticleConstants.LOADTYPE_LOAD_NEW)){
            type = ArticleConstants.LOADTYPE_LOAD_MORE;
        }

        //频道参数校验
        if(StringUtils.isBlank(dto.getTag())){
            dto.setTag(ArticleConstants.DEFAULT_TAG);
        }

        //时间校验
        if(dto.getMaxBehotTime() == null) dto.setMaxBehotTime(new Date());
        if(dto.getMinBehotTime() == null) dto.setMinBehotTime(new Date());

        //2、查询
        List<ApArticle> apArticleList = articleMapper.loadArticleList(dto, type);
        //3、返回结果
        return ResponseResult.okResult(apArticleList);
    }
}
复制代码

 

posted @   佛系粥米  阅读(55)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示