zoukankan      html  css  js  c++  java
  • spring-boot集成Springfox-Swagger2

    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.service.ApiInfo;
    import springfox.documentation.service.Contact;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    import springfox.documentation.swagger2.annotations.EnableSwagger2;
    
    @Configuration
    @EnableSwagger2
    public class Swagger2Config {
    
        @Bean
        public Docket restApiForSensors() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .groupName("sensors data")
                    .forCodeGeneration(true)
                    .select()
    //                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
    //                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                    .paths(PathSelectors.ant("/api/sensors/data/**"))
                    .build()
                    .useDefaultResponseMessages(false);
        }
    
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("倍全SpringBoot Swagger2 RESTful API")
                    .contact(new Contact("hjzgg", "", "2570230521@qq.com"))
                    .description("静态token=xxx")
                    .version("2.0")
                    .build();
        }
    }
    @ApiOperation(value="城市昨日数据总览+城市七天核心数据走势", notes="根据城市和日期展示数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city", value = "城市名称", required = true, paramType = "query"),
            @ApiImplicitParam(name = "date", value = "日期", required = true, paramType = "query"),
            @ApiImplicitParam(name = "token", value = "静态token", required = true, paramType = "query")
    })
    @RequestMapping(value = "index", method = RequestMethod.GET)

    运行效果:访问 http://localhost:8081/sensors-data/swagger-ui.html

    参考资料:

      spring-boot集成Springfox-Swagger2

      Spring - AntPathMatcher

      Spring Swagger2 一些注解说明

  • 相关阅读:
    1250. Check If It Is a Good Array
    380. Insert Delete GetRandom O(1)
    378. Kth Smallest Element in a Sorted Matrix
    341. Flatten Nested List Iterator
    387. First Unique Character in a String
    454. 4Sum II
    D
    勇敢的妞妞 ( 状压 + 思维)
    P1879 [USACO06NOV]玉米田Corn Fields (状压dp入门)
    G
  • 原文地址:https://www.cnblogs.com/hujunzheng/p/6855824.html
Copyright © 2011-2022 走看看