zoukankan      html  css  js  c++  java
  • swagger

    项目中使用到了,所以~~~屎涨了挖茅斯、

    swagger是一个在线的REST风格文档生成和测试的工具,测试方面有像postman一样。

    使用需要配置依赖

    <dependency>
       <groupId>io.springfox</groupId>
       <artifactId>springfox-swagger2</artifactId>
       <version>${version.swagger2}</version>
    </dependency>
    <dependency>
       <groupId>io.springfox</groupId>
       <artifactId>springfox-swagger-ui</artifactId>
       <version>${version.swagger2}</version>
    </dependency>

    设置默认显示api的信息

    @Configuration
    @EnableSwagger2
    public class SwaggerConfiguration {
    
        @Value("${cooker.swagger.enabled}")
        boolean enabled;
    
        @Bean
        public Docket docket() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .enable(enabled)
                    .useDefaultResponseMessages(false)
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.ch.cooker.tob.platform.api.controller"))
                    .paths(PathSelectors.any())
                    .build();
        }
    
        public ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("TOB配送管理平台")
                    .description("TOB配送管理平台接口")
                    .contact(new Contact("Gnoll", "", "136844507@qq.com"))
                    .version("1.0.0")
                    .build();
        }
    }
    

    相关注解

    @Api——用在类上

    @Api(tags = "配送管理平台-供应商")

    @ApiOperation——用在方法上,说明方法的作用

    @ApiOperation(value = "获取供应商列表",notes = "提交方式为application/x-www-form-urlencoded,结果为数组json",responseContainer = "list",response = SupplierDbo.class)

    @ApiResponses——用于表示一组响应

    @ApiResponse——在@ApiResponses用于表达一个错误的响应信息

    @ApiResponses({@ApiResponse(code = 300,message = "参数有误"),@ApiResponse(code = 400,message = "资源未找到")})

    @ApiImplicitParams——用在方法上用来包含一组参数说明

    @ApiImplicitParam——在@ApiImplicitParams用来包含请求参数的各个方面

    @ApiImplicitParams({
          @ApiImplicitParam(name = "id", value = "订单id", required = true, dataTypeClass = Long.class, paramType = "query"),
          @ApiImplicitParam(name = "orderStaute", value = "订单状态  1、待审核 2、已审核 3、备货中 4、拣货中 5、已出库 6、已签收", required = true, dataTypeClass = Integer.class, paramType = "query") })

    @ApiModel——描述一个model的信息(这种一般用在post创建的时候,使用@RequestBody这样的场景,请求参数无法用@ApiImplicitParam进行描述的时候)

    @ApiModel(value = "供应商实体类")

    @ApiModelProperty——描述一个model的属性

    @ApiModelProperty(value = "供应商名称")
    private String name;
    这里:https://blog.xiaomo.info/2016/JavaSpringBootSwaggerUi/
  • 相关阅读:
    设计模式
    WCF 4 安全性和 WIF 简介
    锁,性能调优
    javascript 异步
    javascript的回调函数
    HTML 5 简介
    CSS3 教程
    implementation of python string
    Extending Python with C or C++
    python,deep copy,shallow copy
  • 原文地址:https://www.cnblogs.com/huangzhe1515023110/p/9276092.html
Copyright © 2011-2022 走看看