• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

5.文章详情、使用线程池,更新阅读次数

武飞扬头像
苏七qaq
帮助1

文章详情:

接口url:/articles/view/{id}

请求方式:POST

请求参数:

参数名称 参数类型 说明
id long 文章id(路径参数)

返回数据:

  1.  
    {
  2.  
    "success": true,
  3.  
    "code": 200,
  4.  
    "msg": "success",
  5.  
    "data": "token"
  6.  
    }
ArticleController:
  1.  
    package com.example.blog.controller;
  2.  
     
  3.  
    import com.example.blog.service.ArticleService;
  4.  
    import com.example.blog.vo.Result;
  5.  
    import com.example.blog.vo.params.PageParams;
  6.  
    import org.springframework.beans.factory.annotation.Autowired;
  7.  
    import org.springframework.web.bind.annotation.*;
  8.  
     
  9.  
    @RequestMapping("/articles")
  10.  
    @RestController
  11.  
    public class ArticleController
  12.  
    {
  13.  
     
  14.  
    @Autowired
  15.  
    private ArticleService articleService;
  16.  
    /*如果参数时放在请求体中,application/json传入后台的话,那么后台要用@RequestBody才能接收到;
  17.  
    如果不是放在请求体中的话,那么后台接收前台传过来的参数时,要用@RequestParam来接收。
  18.  
    或者形参前 什么也不写也能接收。*/
  19.  
     
  20.  
    /**
  21.  
    * 文章详情
  22.  
    */
  23.  
    @PostMapping("/view/{id}")
  24.  
    public Result findArticleById(@PathVariable("id") Long articleId)
  25.  
    {
  26.  
    return articleService.findArticleById(articleId);
  27.  
    }
  28.  
    }
学新通
ArticleServiceImpl:
  1.  
    package com.example.blog.service.impl;
  2.  
     
  3.  
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4.  
    import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5.  
    import com.example.blog.dao.mapper.ArticleBodyMapper;
  6.  
    import com.example.blog.dao.mapper.ArticleMapper;
  7.  
    import com.example.blog.dao.mapper.CategoryMapper;
  8.  
    import com.example.blog.dos.Archives;
  9.  
    import com.example.blog.entity.Article;
  10.  
    import com.example.blog.entity.ArticleBody;
  11.  
    import com.example.blog.entity.Category;
  12.  
    import com.example.blog.service.ArticleService;
  13.  
    import com.example.blog.service.CategoryService;
  14.  
    import com.example.blog.service.SysUserService;
  15.  
    import com.example.blog.service.TagService;
  16.  
    import com.example.blog.vo.ArticleBodyVo;
  17.  
    import com.example.blog.vo.ArticleVo;
  18.  
    import com.example.blog.vo.CategoryVo;
  19.  
    import com.example.blog.vo.Result;
  20.  
    import com.example.blog.vo.params.PageParams;
  21.  
    import org.joda.time.DateTime;
  22.  
    import org.springframework.beans.BeanUtils;
  23.  
    import org.springframework.beans.factory.annotation.Autowired;
  24.  
    import org.springframework.stereotype.Service;
  25.  
     
  26.  
    import java.sql.Date;
  27.  
    import java.util.ArrayList;
  28.  
    import java.util.List;
  29.  
     
  30.  
    @Service
  31.  
    public class ArticleServiceImpl implements ArticleService
  32.  
    {
  33.  
     
  34.  
    @Autowired
  35.  
    private ArticleMapper articleMapper;
  36.  
     
  37.  
    @Autowired
  38.  
    private TagService tagService;
  39.  
     
  40.  
    @Autowired
  41.  
    private SysUserService sysUserService;
  42.  
     
  43.  
    @Autowired
  44.  
    private ArticleBodyMapper articleBodyMapper;
  45.  
     
  46.  
    @Autowired
  47.  
    private CategoryService categoryService;
  48.  
    /**
  49.  
    * 分页查询 article数据库表
  50.  
    * @param pageParams
  51.  
    * @return
  52.  
    */
  53.  
    @Override
  54.  
    public Result listArticle(PageParams pageParams)
  55.  
    {
  56.  
    Page<Article> page = new Page<>(pageParams.getPage(), pageParams.getPageSize());
  57.  
    LambdaQueryWrapper<Article> queryWrapper = new LambdaQueryWrapper<>();/*查询器*/
  58.  
    queryWrapper.orderByDesc(Article::getWeight);/*是否置顶进行排序*/
  59.  
    queryWrapper.orderByDesc(Article::getCreateDate);/*根据创建时间进行降序排序 order by create_date desc*/
  60.  
    Page<Article> articlePage = articleMapper.selectPage(page, queryWrapper);/*等同于编写一个普通list查询,mybatis-plus自动替你分页*/
  61.  
    List<Article> records = articlePage.getRecords();
  62.  
    List<ArticleVo> articleVoList = copyList(records,true,true);
  63.  
    return Result.success(articleVoList);
  64.  
    }
  65.  
     
  66.  
    /**
  67.  
    * 将Article列表封装为ArticleVo列表,以便把数据传给前端
  68.  
    * @param records
  69.  
    * @param isTag
  70.  
    * @param isAuthor
  71.  
    * @return
  72.  
    */
  73.  
    private List<ArticleVo> copyList(List<Article> records,boolean isTag,boolean isAuthor)
  74.  
    {
  75.  
    ArrayList<ArticleVo> articleVoList = new ArrayList<>();
  76.  
    for(Article record:records)
  77.  
    {
  78.  
    articleVoList.add(copy(record,isTag,isAuthor,false,false));
  79.  
    }
  80.  
    return articleVoList;
  81.  
    }
  82.  
     
  83.  
     
  84.  
    /*并不是所有接口都需要标签和作者信息*/
  85.  
    private ArticleVo copy(Article article,boolean isTag,boolean isAuthor,boolean isBody,boolean isCategory)
  86.  
    {
  87.  
    ArticleVo articleVo = new ArticleVo();
  88.  
    BeanUtils.copyProperties(article,articleVo);
  89.  
    articleVo.setCreateDate(new DateTime(article.getCreateDate()).toString("yyyy-MM-dd HH:mm"));
  90.  
    /*因为Article中的createDate(Long)与ArticleVo(String)中的createDate类型不同,所以需要进行手动赋值*/
  91.  
    if(isTag)
  92.  
    {
  93.  
    Long articleId = article.getId();
  94.  
    articleVo.setTags(tagService.findTagsById(articleId));
  95.  
    }
  96.  
    if(isAuthor)
  97.  
    {
  98.  
    Long authorId = article.getAuthorId();
  99.  
    articleVo.setAuthor(sysUserService.findUserById(authorId).getNickname());
  100.  
    }
  101.  
    if(isBody)
  102.  
    {
  103.  
    Long bodyId = article.getBodyId();
  104.  
    articleVo.setBody(findArticleBodyById(bodyId));
  105.  
    }
  106.  
    if(isCategory)
  107.  
    {
  108.  
    Long categoryId = article.getCategoryId();
  109.  
    articleVo.setCategory(categoryService.findCategoryById(categoryId));
  110.  
    }
  111.  
    return articleVo;
  112.  
    }
  113.  
     
  114.  
    /**
  115.  
    * 通过文章id 查询文章详情表中的文章详情
  116.  
    * @param bodyId
  117.  
    * @return
  118.  
    */
  119.  
    private ArticleBodyVo findArticleBodyById(Long bodyId)
  120.  
    {
  121.  
    ArticleBody articleBody = articleBodyMapper.selectById(bodyId);
  122.  
    ArticleBodyVo articleBodyVo = new ArticleBodyVo();
  123.  
    articleBodyVo.setContent(articleBody.getContent());
  124.  
    return articleBodyVo;
  125.  
    }
  126.  
     
  127.  
     
  128.  
    /**
  129.  
    * 文章详情
  130.  
    * @param articleId
  131.  
    * @return
  132.  
    */
  133.  
    @Override
  134.  
    public Result findArticleById(Long articleId)
  135.  
    {
  136.  
    /**
  137.  
    * 1.把ArticleVo对应的ArticleBodyVo 和categories注释去掉,也就是现在需要使用这两个成员,并添加对应的Vo类
  138.  
    * 2.根据articleId查询文章article
  139.  
    * 3.根据bodyId 和categoryId 去关联查询对应的文章详情和文章标签
  140.  
    * 4.将查到的文章详情和文章标签注入到articleVo中
  141.  
    */
  142.  
    Article article = articleMapper.selectById(articleId);
  143.  
     
  144.  
    ArticleVo articleVo = copy(article, true, true,true,true);
  145.  
    return Result.success(articleVo);
  146.  
    }
  147.  
    }
学新通

这里有一点复杂,理一下逻辑

1.把ArticleVo对应的ArticleBodyVo 和category注释去掉,也就是现在需要使用这两个成员(文章详情和文章分类),并添加对应的Vo类

1.1ArticleVo:

  1.  
    package com.example.blog.vo;
  2.  
     
  3.  
     
  4.  
    import lombok.Data;
  5.  
     
  6.  
    import java.util.List;
  7.  
     
  8.  
    @Data
  9.  
    public class ArticleVo
  10.  
    {
  11.  
     
  12.  
    // @JsonSerialize(using = ToStringSerializer.class)
  13.  
    private String id;
  14.  
     
  15.  
    private String title;
  16.  
     
  17.  
    private String summary;
  18.  
     
  19.  
    private Integer commentCounts;
  20.  
     
  21.  
    private Integer viewCounts;
  22.  
     
  23.  
    private Integer weight;
  24.  
    /**
  25.  
    * 创建时间
  26.  
    */
  27.  
    private String createDate;
  28.  
     
  29.  
    private String author;
  30.  
    /*创建该文章的作者头像*/
  31.  
    private String avatar;
  32.  
     
  33.  
    private String authorId;
  34.  
     
  35.  
    private ArticleBodyVo body;
  36.  
     
  37.  
    private List<TagVo> tags;/*文章标签*/
  38.  
     
  39.  
    private CategoryVo categoryVo;
  40.  
    }
学新通

 1.2 ArticleBodyVo

  1.  
    package com.example.blog.vo;
  2.  
     
  3.  
    import lombok.Data;
  4.  
     
  5.  
    @Data
  6.  
    public class ArticleBodyVo
  7.  
    {
  8.  
    private String content;
  9.  
    }

1.3  CategoryVo

  1.  
    package com.example.blog.vo;
  2.  
     
  3.  
    import lombok.Data;
  4.  
     
  5.  
    @Data
  6.  
    public class CategoryVo
  7.  
    {
  8.  
    private String id;
  9.  
     
  10.  
    private String avatar;
  11.  
     
  12.  
    private String categoryName;
  13.  
     
  14.  
    }

2.根据articleId查询文章article,获取对应的bodyId和categoryId

3.根据bodyId 和categoryId 去关联查询对应的文章详情和文章标签 

ArticleServiceImpl:

  1.  
    /**
  2.  
    * 通过文章id 查询文章详情表中的文章详情
  3.  
    * @param bodyId
  4.  
    * @return
  5.  
    */
  6.  
    private ArticleBodyVo findArticleBodyById(Long bodyId)
  7.  
    {
  8.  
    ArticleBody articleBody = articleBodyMapper.selectById(bodyId);
  9.  
    ArticleBodyVo articleBodyVo = new ArticleBodyVo();
  10.  
    articleBodyVo.setContent(articleBody.getContent());
  11.  
    return articleBodyVo;
  12.  
    }
CategoryServiceImpl:
  1.  
    package com.example.blog.service.impl;
  2.  
     
  3.  
    import com.example.blog.dao.mapper.CategoryMapper;
  4.  
    import com.example.blog.entity.Category;
  5.  
    import com.example.blog.service.CategoryService;
  6.  
    import com.example.blog.vo.CategoryVo;
  7.  
    import org.springframework.beans.BeanUtils;
  8.  
    import org.springframework.beans.factory.annotation.Autowired;
  9.  
    import org.springframework.stereotype.Service;
  10.  
     
  11.  
    import java.util.List;
  12.  
     
  13.  
    @Service
  14.  
    public class CategoryServiceImpl implements CategoryService
  15.  
    {
  16.  
     
  17.  
    @Autowired
  18.  
    private CategoryMapper categoryMapper;
  19.  
     
  20.  
    @Override
  21.  
    public CategoryVo findCategoryById(Long categoryId)
  22.  
    {
  23.  
    Category category = categoryMapper.selectById(categoryId);
  24.  
    return copy(category);
  25.  
    }
  26.  
     
  27.  
    private CategoryVo copy(Category category)
  28.  
    {
  29.  
    CategoryVo categoryVo = new CategoryVo();
  30.  
    BeanUtils.copyProperties(category,categoryVo);
  31.  
    return categoryVo;
  32.  
    }
  33.  
    }
学新通

4.将查到的文章详情和文章标签注入到articleVo中

ArticleVo articleVo = copy(article, true, true,true,true);
  1.  
    /*并不是所有接口都需要标签和作者信息*/
  2.  
    private ArticleVo copy(Article article,boolean isTag,boolean isAuthor,boolean isBody,boolean isCategory)
  3.  
    {
  4.  
    ArticleVo articleVo = new ArticleVo();
  5.  
    BeanUtils.copyProperties(article,articleVo);/*可以理解为article相同成员赋值给articleVo*/
  6.  
    /*BeanUtils.copyProperties(article, articleVo);
  7.  
    articleVo中的存在的属性,article中一定要有,但是article中可以有多余的属性;
  8.  
    article中与articleVo中相同的属性都会被替换,不管是否有值;
  9.  
    article、articleVo中的属性要名字相同,才能被赋值,不然的话需要手动赋值;
  10.  
    Spring的BeanUtils的CopyProperties方法需要对应的属性有getter和setter方法;
  11.  
    如果存在属性完全相同的内部类,但是不是同一个内部类,即分别属于各自的内部类,则spring会认为属性不同,不会copy*/
  12.  
    articleVo.setCreateDate(new DateTime(article.getCreateDate()).toString("yyyy-MM-dd HH:mm"));
  13.  
    /*因为Article中的createDate(Long)与ArticleVo(String)中的createDate类型不同,所以需要进行手动赋值*/
  14.  
    if(isTag)
  15.  
    {
  16.  
    Long articleId = article.getId();
  17.  
    articleVo.setTags(tagService.findTagsById(articleId));
  18.  
    }
  19.  
    if(isAuthor)
  20.  
    {
  21.  
    Long authorId = article.getAuthorId();
  22.  
    articleVo.setAuthor(sysUserService.findUserById(authorId).getNickname());
  23.  
    }
  24.  
    if(isBody)
  25.  
    {
  26.  
    Long bodyId = article.getBodyId();
  27.  
    articleVo.setBody(findArticleBodyById(bodyId));
  28.  
    }
  29.  
    if(isCategory)
  30.  
    {
  31.  
    Long categoryId = article.getCategoryId();
  32.  
    articleVo.setCategory(categoryService.findCategoryById(categoryId));
  33.  
    }
  34.  
    return articleVo;
  35.  
    }
学新通

5.重点!!

==>  Preparing:

SELECT id,title,summary,comment_counts,view_counts,author_id,body_id,category_id,weight,create_date FROM ms_article WHERE id=?
==> Parameters: 1405564731300831200(Long)
<==      Total: 0

学新通

发现:前端传入的值1405564731300831200丢失了两位精度,所以前端传入的articleId,后端通过该id找不到对应的article!!!

原因:由于前端传入的articleId丢失了精度,java中long数据能表示的范围比js中number大,在跟前端交互时,这样也就意味着部分数值在js中存不下(变成不准确的值)。

解决方案:ArticleVo 中的id字段使用fastjson的ToStringSerializer注解,让系统序列化时,保留相关精度。

  1.  
    package com.example.blog.vo;
  2.  
     
  3.  
     
  4.  
    import lombok.Data;
  5.  
     
  6.  
    import java.util.List;
  7.  
     
  8.  
    @Data
  9.  
    public class ArticleVo
  10.  
    {
  11.  
     
  12.  
    // @JsonSerialize(using = ToStringSerializer.class)
  13.  
    private String id;
  14.  
     
  15.  
    private String title;
  16.  
     
  17.  
    private String summary;
  18.  
     
  19.  
    private Integer commentCounts;
  20.  
     
  21.  
    private Integer viewCounts;
  22.  
     
  23.  
    private Integer weight;
  24.  
    /**
  25.  
    * 创建时间
  26.  
    */
  27.  
    private String createDate;
  28.  
     
  29.  
    private String author;
  30.  
    /*创建该文章的作者头像*/
  31.  
    private String avatar;
  32.  
     
  33.  
    private String authorId;
  34.  
     
  35.  
    private ArticleBodyVo body;
  36.  
     
  37.  
    private List<TagVo> tags;/*文章标签*/
  38.  
     
  39.  
    private CategoryVo categoryVo;
  40.  
    }
学新通

学新通

 这里阅读数应该随着点击增加,所以需要使用线程池,更新阅读次数

查看完该文章之后,本应该直接返回数据,这个时候做了一个更新操作,更新时加写锁,阻塞其他的读操作,性能就会比较低。

更新肯定会增加此次接口的耗时,如果更新一旦除了问题,不能影响查看文章的操作。

这时可以增加线程池,把更新操作扔到线程池中去执行,这样就和主线程不相关了。

创建一个线程池:

  1.  
    package com.example.blog.cofig;
  2.  
     
  3.  
    import org.springframework.context.annotation.Bean;
  4.  
    import org.springframework.context.annotation.Configuration;
  5.  
    import org.springframework.scheduling.annotation.EnableAsync;
  6.  
    import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
  7.  
     
  8.  
    import java.util.concurrent.Executor;
  9.  
    import java.util.concurrent.ThreadPoolExecutor;
  10.  
     
  11.  
    @Configuration
  12.  
    @EnableAsync //开启多线程
  13.  
    public class ThreadPoolConfig
  14.  
    {
  15.  
    @Bean("taskExcutor")
  16.  
    public Executor asyncServiceExecutor()
  17.  
    {
  18.  
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
  19.  
    // 设置核心线程数
  20.  
    executor.setCorePoolSize(5);
  21.  
    // 设置最大线程数
  22.  
    executor.setMaxPoolSize(20);
  23.  
    //配置队列大小
  24.  
    executor.setQueueCapacity(Integer.MAX_VALUE);
  25.  
    // 设置线程活跃时间(秒)
  26.  
    executor.setKeepAliveSeconds(60);
  27.  
    // 设置默认线程名称
  28.  
    executor.setThreadNamePrefix("博客");
  29.  
    // 等待所有任务结束后再关闭线程池
  30.  
    executor.setWaitForTasksToCompleteOnShutdown(true);
  31.  
    //执行初始化
  32.  
    executor.initialize();
  33.  
    return executor;
  34.  
    }
  35.  
    }
学新通

ArticleServiceImpl中的显示文章详情的方法findArticleById中,添加一个线程池,用于增加阅读量

  1.  
    @Autowired
  2.  
    private ThreadService threadService;
  3.  
    @Override
  4.  
    public Result findArticleById(Long articleId)
  5.  
    {
  6.  
    /**
  7.  
    * 1.把ArticleVo对应的ArticleBodyVo 和categories注释去掉,也就是现在需要使用这两个成员,并添加对应的Vo类
  8.  
    * 2.根据articleId查询文章article
  9.  
    * 3.根据bodyId 和categoryId 去关联查询对应的文章详情和文章标签
  10.  
    * 4.将查到的文章详情和文章标签注入到articleVo中
  11.  
    */
  12.  
    Article article = articleMapper.selectById(articleId);
  13.  
    ArticleVo articleVo = copy(article, true, true,true,true);
  14.  
    //查看完该文章之后,本应该直接返回数据,这个时候做了一个更新操作,更新时加写锁,阻塞其他的读操作,性能就会比较低
  15.  
    //更新肯定会增加此次接口的耗时,如果更新一旦除了问题,不能影响 查看文章的操作
  16.  
    //这时可以增加线程池,把更新操作扔到线程池中去执行,这样就和主线程不相关了
  17.  
    threadService.updateArticleViewCount(articleMapper,article);
  18.  
    return Result.success(articleVo);
  19.  
    }
学新通
ThreadService:
  1.  
    package com.example.blog.service;
  2.  
     
  3.  
    import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  4.  
    import com.example.blog.dao.mapper.ArticleMapper;
  5.  
    import com.example.blog.entity.Article;
  6.  
    import org.springframework.scheduling.annotation.Async;
  7.  
    import org.springframework.stereotype.Component;
  8.  
     
  9.  
    @Component
  10.  
    public class ThreadService
  11.  
    {
  12.  
    //期望此次操作在线程池执行 不会影响原有的主线程
  13.  
    @Async("taskExcutor")//将该任务丢到线程池中
  14.  
    public void updateArticleViewCount(ArticleMapper articleMapper, Article article)
  15.  
    {
  16.  
    int viewCounts = article.getViewCounts();
  17.  
     
  18.  
    Article articleUpdate = new Article();
  19.  
    articleUpdate.setViewCounts(viewCounts 1);
  20.  
    LambdaUpdateWrapper<Article> updateWrapper = new LambdaUpdateWrapper<>();
  21.  
    updateWrapper.eq(Article::getId,article.getId());
  22.  
    //设置一个 为了在多线程的环境下 线程安全
  23.  
    //乐观锁的一个思想 如果操作的时候发现阅读数与期望的阅读数不一致,修改失败
  24.  
    updateWrapper.eq(Article::getViewCounts,viewCounts);
  25.  
     
  26.  
    articleMapper.update(articleUpdate,updateWrapper);
  27.  
    try {
  28.  
    //睡眠 ThredService中的方法 5秒,不会影响主线程的使用,即文章详情会很快的显示出来,不受影响
  29.  
    Thread.sleep(5000);
  30.  
    System.out.println("更新完成了~~~");
  31.  
    } catch (InterruptedException e) {
  32.  
    e.printStackTrace();
  33.  
    }
  34.  
    }
  35.  
    }
学新通

这里有一个Bug

由于article类中的commentCounts,viewCounts,weight 字段为int

  1.  
    package com.example.blog.entity;
  2.  
     
  3.  
    import lombok.Data;
  4.  
     
  5.  
    @Data
  6.  
    public class Article {
  7.  
     
  8.  
    public static final int Article_TOP = 1;
  9.  
     
  10.  
    public static final int Article_Common = 0;
  11.  
     
  12.  
    private Long id;
  13.  
     
  14.  
    private String title;
  15.  
     
  16.  
    private String summary;
  17.  
     
  18.  
    private int commentCounts;
  19.  
     
  20.  
    private int viewCounts;
  21.  
     
  22.  
    /**
  23.  
    * 作者id
  24.  
    */
  25.  
    private Long authorId;
  26.  
    /**
  27.  
    * 内容id
  28.  
    */
  29.  
    private Long bodyId;
  30.  
    /**
  31.  
    *类别id
  32.  
    */
  33.  
    private Long categoryId;
  34.  
     
  35.  
    /**
  36.  
    * 置顶
  37.  
    */
  38.  
    private int weight = Article_Common;
  39.  
     
  40.  
     
  41.  
    /**
  42.  
    * 创建时间
  43.  
    */
  44.  
    private Long createDate;
  45.  
    }
学新通

发现:会造成更新阅读次数的时候,将commentCounts,viewCounts,weight 字段设为初始值0,也就是这条语句

articleMapper.update(articleUpdate,updateWrapper);

原因:在更新阅读次数的时候,只要该成员值不为null,mybatisPlus都会把该成员赋值进去更新,也就是把commentCounts,viewCounts,weight这三个int类型的赋值进去

解决:如果设置为integer,该成员值就为null,就不会被更新

总结:需要把与数据库对应字段的成员设置为integer,而不是int类型

修改:

  1.  
    package com.example.blog.entity;
  2.  
     
  3.  
    import lombok.Data;
  4.  
     
  5.  
    @Data
  6.  
    public class Article {
  7.  
     
  8.  
    public static final int Article_TOP = 1;
  9.  
     
  10.  
    public static final int Article_Common = 0;
  11.  
     
  12.  
    private Long id;
  13.  
     
  14.  
    private String title;
  15.  
     
  16.  
    private String summary;
  17.  
     
  18.  
    private Integer commentCounts;
  19.  
     
  20.  
    private Integer viewCounts;
  21.  
     
  22.  
    /**
  23.  
    * 作者id
  24.  
    */
  25.  
    private Long authorId;
  26.  
    /**
  27.  
    * 内容id
  28.  
    */
  29.  
    private Long bodyId;
  30.  
    /**
  31.  
    *类别id
  32.  
    */
  33.  
    private Long categoryId;
  34.  
     
  35.  
    /**
  36.  
    * 置顶
  37.  
    */
  38.  
    private Integer weight;
  39.  
     
  40.  
     
  41.  
    /**
  42.  
    * 创建时间
  43.  
    */
  44.  
    private Long createDate;
  45.  
    }
学新通

以及对应vo

  1.  
    package com.example.blog.vo;
  2.  
     
  3.  
     
  4.  
    import lombok.Data;
  5.  
     
  6.  
    import java.util.List;
  7.  
     
  8.  
    @Data
  9.  
    public class ArticleVo
  10.  
    {
  11.  
     
  12.  
    // @JsonSerialize(using = ToStringSerializer.class)
  13.  
    private String id;
  14.  
     
  15.  
    private String title;
  16.  
     
  17.  
    private String summary;
  18.  
     
  19.  
    private Integer commentCounts;
  20.  
     
  21.  
    private Integer viewCounts;
  22.  
     
  23.  
    private Integer weight;
  24.  
    /**
  25.  
    * 创建时间
  26.  
    */
  27.  
    private String createDate;
  28.  
     
  29.  
    private String author;
  30.  
    /*创建该文章的作者头像*/
  31.  
    private String avatar;
  32.  
     
  33.  
    private String authorId;
  34.  
     
  35.  
    private ArticleBodyVo body;
  36.  
     
  37.  
    private List<TagVo> tags;/*文章标签*/
  38.  
     
  39.  
    private CategoryVo categoryVo;
  40.  
    }
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgeibbc
系列文章
更多 icon
同类精品
更多 icon
继续加载