zoukankan      html  css  js  c++  java
  • spring boot 中使用swagger 来自动生成接口文档

    1.依赖包

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.6.1</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.6.1</version>
    </dependency>
    

    2.配置类

    package com.shinyway.workflow;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import springfox.documentation.builders.ApiInfoBuilder;
    import springfox.documentation.builders.PathSelectors;
    import springfox.documentation.builders.RequestHandlerSelectors;
    import springfox.documentation.service.ApiInfo;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    import springfox.documentation.swagger2.annotations.EnableSwagger2;
    
    @Configuration
    @EnableSwagger2
    public class Swagger2Configuration {
    
        @Bean
        public Docket createRestApi() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.shinyway"))
                    .paths(PathSelectors.any())
                    .build();
        }
    
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("审批平台API")
                    .description("审批平台API")
                    .version("1.0")
                    .build();
        }
    
    }

    3.controller中的方法上加上注解

        @ApiOperation(value="获取审批意见列表(html格式)", notes="通过业务号获取意见列表")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "processDefinitionKey", value = "流程定义标识", required = true, dataType = "String"),
                @ApiImplicitParam(name = "businessKey", value = "业务号", required = true, dataType = "String")
        })

    4.如果一一些方法或者整个类不需要提供文档,可以在方法或者类上加上@ApiIgnore注解

  • 相关阅读:
    读取.robot文件写入excel文件中示例
    提示框、滚动条处理与JS的应用
    下拉框
    切换框架ifame
    层级定位
    定位一组元素
    Appium元素定位方法
    python+appium基本启动配置
    adb命令使用
    Python接口测试框架搭建
  • 原文地址:https://www.cnblogs.com/sigm/p/7728507.html
Copyright © 2011-2022 走看看