接口文档神器---SpringBoot整合Swagger

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);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值