测试后端接口

1.查询实例

1.1代码接口定义

     /**
     * 根据id查看文章
     *
     * @param articleId 文章id
     * @return {@link Result<ArticleDTO>} 文章信息
     */
    @ApiOperation(value = "根据id查看文章")
    @ApiImplicitParam(name = "articleId", value = "文章id", required = true, dataType = "Integer")
    @GetMapping("/articles/{articleId}")
    public Result<ArticleDTO> getArticleById(@PathVariable("articleId") Integer articleId) {
        return Result.ok(articleService.getArticleById(articleId));
    }

1.2错误示例 根据id查看文章

http://localhost/articles?articleId=60
image.png
image.pngimage.png

1.3正确写法

http://localhost/articleId/60

1.4总结

@PathVariable直接/填入需要查询的ok了

2.实现登录

http://localhost:8080/login?username=shisan@163.com&password=123456

在query中输入
在body中输入因为视频是在这里面输入的

3.实现新增文章

3.1接口定义

/**
     * 添加或修改文章
     *
     * @param articleVO 文章信息
     * @return {@link Result<>}
     */
    @OptLog(optType = SAVE_OR_UPDATE)
    @ApiOperation(value = "添加或修改文章")
    @PostMapping("/admin/articles")
    public Result<?> saveOrUpdateArticle(@Valid @RequestBody ArticleVO articleVO) {
        articleService.saveOrUpdateArticle(articleVO);
        return Result.ok();
    }

3.2成功案例

{
    "articleContent":"4-18",
    "articleCover":null,
    "articleTitle":"4-18",
    "categoryName":"java编程",
    "id":"60","isTop":"0",
    "originalUrl":"String",
    "status":"1",
    "tagNameList":null,
    "type":"1",
    "createTime":"2021-10-31 16:35:22"
}

tagNameList是一个list所以其需要["Vue","微服务"]写标签

3.3总结

@RequestBody 中需要用body输入,并且注意List的写法

posted on 2022-04-20 10:33  stuMartin  阅读(41)  评论(0编辑  收藏  举报

导航