如果现在想要测试护理项目,我们发现在swagger中并没有护理项目相关的接口,如果想要展示这些接口,我们需要添加上必要的注解来进行说明才能阅读和访问。
常见注解
通过注解可以控制生成的接口文档,使接口文档拥有更好的可读性,常用注解如下:
注解
说明
@Api
用在类上,描述Controller的作用
@ApiOperation
用在方法上,说明方法的用途、作用
@ApiParam
用在方法的参数上,描述单个形参的含义,适用于简单场景
@ApiImplicitParam
用在方法上,描述单个形参的含义,适用于参数复杂或者不是通过方法参数传递的场景
@ApiModel
用在类上,用对象来接收参数或者返回参数,描述类的含义
@ApiModelProperty
用在类的属性上,用对象来接收参数或者返回参数,描述字段的含义
Controller的方法参数说明
我们熟悉了这些注解之后,我们可以让AI协助我们快速完成注解的编写:
Prompt
把整个NursingProjectController类给AI,然后在最后添加上一句话:
帮我给上述代码添加上swagger注解说明,要求每个参数也要进行说明,如:@Api、@ApiOperation、@ApiParam
生成后的代码如下【建议看懂之后直接CV】:
Java
运行代码
复制代码
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.zzyl.serve.controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@RestController
@RequestMapping("/serve/project")
@Api(tags = "护理项目管理") // 控制器级别的标签描述
public class NursingProjectController extends BaseController {
@Autowired
private INursingProjectService nursingProjectService;
/**
* 查询护理项目列表
*/
@PreAuthorize("@ss.hasPermi('serve:project:list')")
@GetMapping("/list")
@ApiOperation("查询护理项目列表")
public TableDataInfo list(
@ApiParam(name = "nursingProject", value = "护理项目实体类,用于条件筛选") NursingProject nursingProject) {
startPage();
List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
return getDataTable(list);
}
/**
* 导出护理项目列表
*/
@PreAuthorize("@ss.hasPermi('serve:project:export')")
@Log(title = "护理项目", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@ApiOperation("导出护理项目数据到Excel")
public void export(
@ApiParam(name = "response", value = "HTTP响应对象,用于输出Excel文件") HttpServletResponse response,
@ApiParam(name = "nursingProject", value = "护理项目实体类,用于条件筛选") NursingProject nursingProject) {
List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
ExcelUtil<NursingProject> util = new ExcelUtil(NursingProject.class);
util.exportExcel(response, list, "护理项目数据");
}
/**
* 获取护理项目详细信息
*/
@PreAuthorize("@ss.hasPermi('serve:project:query')")
@GetMapping(value = "/{id}")
@ApiOperation("根据ID获取护理项目详细信息")
public AjaxResult getInfo(
@ApiParam(name = "id", value = "护理项目唯一标识", required = true) @PathVariable("id") Long id) {
return success(nursingProjectService.selectNursingProjectById(id));
}
/**
* 新增护理项目
*/
@PreAuthorize("@ss.hasPermi('serve:project:add')")
@Log(title = "护理项目", businessType = BusinessType.INSERT)
@PostMapping
@ApiOperation("新增护理项目")
public AjaxResult add(
@ApiParam(name = "nursingProject", value = "护理项目实体类,包含新增数据", required = true) @RequestBody NursingProject nursingProject) {
return toAjax(nursingProjectService.insertNursingProject(nursingProject));
}
/**
* 修改护理项目
*/
@PreAuthorize("@ss.hasPermi('serve:project:edit')")
@Log(title = "护理项目", businessType = BusinessType.UPDATE)
@PutMapping
@ApiOperation("修改护理项目")
public AjaxResult edit(
@ApiParam(name = "nursingProject", value = "护理项目实体类,包含修改数据", required = true) @RequestBody NursingProject nursingProject) {
return toAjax(nursingProjectService.updateNursingProject(nursingProject));
}
/**
* 删除护理项目
*/
@PreAuthorize("@ss.hasPermi('serve:project:remove')")
@Log(title = "护理项目", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
@ApiOperation("删除护理项目(支持批量)")
public AjaxResult remove(
@ApiParam(name = "ids", value = "护理项目ID数组,表示要删除的多个项目", required = true) @PathVariable Long[] ids) {
return toAjax(nursingProjectService.deleteNursingProjectByIds(ids));
}
}