栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

在线博客系统——最热文章、最新文章

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在线博客系统——最热文章、最新文章

目录

最热文章

接口说明

编码实现

配置类application.properties

Controller控制层

Service业务逻辑层

前端测试

最新文章

接口说明

编码实现

Controller控制层

Service业务逻辑层

前端测试


最热文章

接口说明

接口url:/articles/hot

请求方式:POST

请求参数:无

返回数据:

{
    "success": true,
    "code": 200,
    "msg": "success",
    "data": [
        {
            "id": 1,
            "title": "springboot介绍以及入门案例",
        },
        {
            "id": 9,
            "title": "Vue.js 是什么",
        },
        {
            "id": 10,
            "title": "Element相关",
            
        }
    ]
}

编码实现

配置类application.properties
#   spring读取配置文件的数据:@Value("${tag.hot.limit}")
#设置tag最热标签个数
tag.hot.limit=6
#设置Article最热文章个数
article.hotAndNew.limit=6

Controller控制层

ArticleController:

    
    @PostMapping("hot")
    public Result hotArticle(){
        return articleService.hotArticle(limit);
    }

Service业务逻辑层

接口ArticleService:

    
    Result hotArticle(int limit);

实现类ArticleServiceImpl:

@Override
    public Result hotArticle(int limit) {
        LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(Article::getViewCounts);
        queryWrapper.select(Article::getId, Article::getTitle);
        queryWrapper.last("limit " + limit);
        List articles = articleMapper.selectList(queryWrapper);
        return Result.success(copyList(articles,false,false));
    }

前端测试

最新文章 接口说明

接口url:/articles/new

请求方式:POST

请求参数:无

返回数据:

{
    "success": true,
    "code": 200,
    "msg": "success",
    "data": [
        {
            "id": 1,
            "title": "springboot介绍以及入门案例",
        },
        {
            "id": 9,
            "title": "Vue.js 是什么",
        },
        {
            "id": 10,
            "title": "Element相关",
            
        }
    ]
}
编码实现 Controller控制层

ArticleController

    
    @PostMapping("new")
    public Result newArticle(){
        return  articleService.newArticle(limit);
    }
Service业务逻辑层

ArticleService接口:

    
    Result newArticle(int limit);

ArticleServiceImpl实现类:

    @Override
    public Result newArticle(int limit) {
        LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(Article::getId,Article::getTitle);
        queryWrapper.orderByDesc(Article::getCreateDate);
        queryWrapper.last("limit " + limit);
        List articles = articleMapper.selectList(queryWrapper);
        return Result.success(copyList(articles,false,false));
    }

前端测试

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1006321.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号