获取文章详情接口
3.3.1 基本信息
请求路径:/article/detail
请求方式:GET
接口描述:该接口用于根据ID获取文章详细信息
3.3.2 请求参数
请求参数格式:queryString
请求参数说明:
参数名称 | 说明 | 类型 | 是否必须 | 备注 | |
---|---|---|---|---|---|
id | 主键ID | number | 是 |
请求数据样例:
id=4
3.3.3 响应数据
响应数据类型:application/json
响应参数说明:
名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 |
---|---|---|---|---|---|
code | number | 必须 | 响应码, 0-成功,1-失败 | ||
message | string | 非必须 | 提示信息 | ||
data | object | 必须 | 返回的数据 | ||
|-id | number | 非必须 | 主键ID | ||
|-title | string | 非必须 | 文章标题 | ||
|-content | string | 非必须 | 文章正文 | ||
|-coverImg | string | 非必须 | 文章封面图像地址 | ||
|-state | string | 非必须 | 发布状态 | 已发布|草稿 | |
|-categoryId | number | 非必须 | 文章分类ID | ||
|-createTime | string | 非必须 | 创建时间 | ||
|-updateTime | string | 非必须 | 更新时间 |
响应数据样例:
{
"code": 0,
"message": "操作成功",
"data": {
"id": 4,
"title": "北京旅游攻略",
"content": "天安门,颐和园,鸟巢,长城...爱去哪去哪...",
"coverImg": "https://big-event-gwd.oss-cn-beijing.aliyuncs.com/9bf1cf5b-1420-4c1b-91ad-e0f4631cbed4.png",
"state": "已发布",
"categoryId": 2,
"createTime": "2023-09-03 11:35:04",
"updateTime": "2023-09-03 11:40:31"
}
}
更新文章接口
3.4 更新文章
3.4.1 基本信息
请求路径:/article
请求方式:PUT
接口描述:该接口用于更新文章信息
3.4.2 请求参数
请求参数格式:application/json
请求参数说明:
参数名称 | 说明 | 类型 | 是否必须 | 备注 | |
---|---|---|---|---|---|
id | 主键ID | number | 是 | ||
title | 文章标题 | string | 是 | ||
content | 文章正文 | string | 是 | ||
coverImg | 封面图像地址 | string | 是 | ||
state | 发布状态 | string | 是 | 已发布 | 草稿 | |
categoryId | 文章分类ID | number | 是 |
请求数据样例:
{
"id":4,
"title": "北京旅游攻略",
"content": "天安门,颐和园,鸟巢,长城...爱去哪去哪...",
"coverImg": "https://big-event-gwd.oss-cn-beijing.aliyuncs.com/9bf1cf5b-1420-4c1b-91ad-e0f4631cbed4.png",
"state": "已发布",
"categoryId": 2
}
3.4.3 响应数据
响应数据类型:application/json
响应参数说明:
名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 |
---|---|---|---|---|---|
code | number | 必须 | 响应码, 0-成功,1-失败 | ||
message | string | 非必须 | 提示信息 | ||
data | object | 非必须 | 返回的数据 |
响应数据样例:
{
"code": 0,
"message": "操作成功",
"data": null
}
删除文章接口
3.5 删除文章
3.5.1 基本信息
请求路径:/article
请求方式:DELETE
接口描述:该接口用于根据ID删除文章
3.5.2 请求参数
请求参数格式:queryString
请求参数说明:
参数名称 | 说明 | 类型 | 是否必须 | 备注 | |
---|---|---|---|---|---|
id | 主键ID | number | 是 |
请求数据样例:
id=4
3.5.3 响应数据
响应数据类型:application/json
响应参数说明:
名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 |
---|---|---|---|---|---|
code | number | 必须 | 响应码, 0-成功,1-失败 | ||
message | string | 非必须 | 提示信息 | ||
data | object | 非必须 | 返回的数据 |
响应数据样例:
{
"code": 0,
"message": "操作成功",
"data": null
}
代码(按顺序)
- controller
@GetMapping("/detail")
public Result<Article> detail(@RequestParam Integer id) {
Article as = articleService.detail(id);
return Result.success(as);
}
@PutMapping
public Result update(@RequestBody @Validated Article article) {
articleService.update(article);
return Result.success();
}
@DeleteMapping
public Result delete(@RequestParam Integer id) {
articleService.delete(id);
return Result.success();
}
- service
Article detail(Integer id);
void update(Article article);
void delete(Integer id);
- serviceImpl
@Override
public Article detail(Integer id) {
Article as = articleMapper.detail(id);
return as;
}
@Override
public void update(Article article) {
articleMapper.update(article);
}
@Override
public void delete(Integer id) {
articleMapper.delete(id);
}
- mapper
@Select("select * from article where id = #{id}")
Article detail(Integer id);
@Update("update article set title=#{title}, content=#{content}, cover_img=#{coverImg}, state=#{state}, category_id=#{categoryId} where id = #{id}")
void update(Article article);
@Delete("delete from article where id = #{id}")
void delete(Integer id);