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 一些注解说明

  • 相关阅读:
    算法作业实验三
    牛客练习赛53 B 美味果冻
    牛客练习赛53 C 富豪凯匹配串
    bitmat
    牛客挑战赛33 B 鸽天的放鸽序列
    树状数组
    线段树
    2019牛客国庆集训派对day7 A 2016
    背包
    作业三 -并查集
  • 原文地址:https://www.cnblogs.com/hujunzheng/p/6855824.html
Copyright © 2011-2022 走看看