SpringBoot整合Swagger
整合步骤
- 引入Swagger依赖库,可以从maven仓库下载,仓库地址
<!-- Swagger依赖-->
<!-- 增加swagger配置 -->
<!-- Swagger依赖-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
-
整合Swagger的属性配置
-
Swagger常用注解
整合实践
- 在Controller的类中使用Swagger注解
- 在Controller的方法中使用Swagger的注解
- 在Controller的参数中使用Swagger的注解
@RestController
@RequestMapping("/theme")
@Api(value = "主题信息相关接口", tags = "主题信息相关接口")
public class ThemeInfoController {
@Autowired
private ThemeInfoService themeInfoService;
/**
* 主题的保存、编辑
*/
@PostMapping("/saveOrUpdateTheme")
@ApiOperation(value = "主题的保存或编辑", notes = "主题的保存或编辑", produces = "application/json")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Suceess|OK"),
@ApiResponse(code = 401, message = "not authorized!"),
@ApiResponse(code = 403, message = "forbidden!!!"),
@ApiResponse(code = 404, message = "not found!!!") })
public BaseResult saveOrUpdateTheme(@ApiParam(name = "themeInfo",required = true) @RequestBody ThemeInfo themeInfo){
return themeInfoService.saveOrUpdateTheme(themeInfo);
}
/**
* 主题的删除
* 根据主题编号id删除主题
*/
@PostMapping("/deleteThemeById")
@ApiOperation(value = "根据主题编号id删除主题", notes = "根据主题编号id删除主题", produces = "application/json")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Suceess|OK"),
@ApiResponse(code = 401, message = "not authorized!"),
@ApiResponse(code = 403, message = "forbidden!!!"),
@ApiResponse(code = 404, message = "not found!!!") })
public BaseResult deleteThemeById(@ApiParam(name = "ids",required = true)@RequestBody List<String> ids){
return themeInfoService.deleteThemeById(ids);
}
/**
* 主题的查询
*/
@PostMapping("/getThemeInfo")
@ApiOperation(value = "根据主题编号id删除主题", notes = "根据主题编号id删除主题", produces = "application/json")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Suceess|OK"),
@ApiResponse(code = 401, message = "not authorized!"),
@ApiResponse(code = 403, message = "forbidden!!!"),
@ApiResponse(code = 404, message = "not found!!!") })
public BaseResult<Page<ThemeInfo>> getThemeInfo(@ApiParam(name = "themeInfoValidator",required = true)@RequestBody ThemeInfoValidator themeInfoValidator){
return themeInfoService.getThemeInfo(themeInfoValidator);
}