Swagger基础学习

    技术2022-07-11  79

    Swagger使用教程

    API框架

    Restful文档自动生成工具,API文档与定义的同步更新

    SpringBoot集成Swagger

    使用两个库

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

    Sprinboot里面添加SwaggerConfi

    @Configuration @EnableSwagger2 public class SwaggerConfig { // @Bean public Docket docket(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()); } //修改默认配置 private ApiInfo apiInfo(){ //作者信息 Contact contact = new Contact("wildec", "", "zkj823743791@qq.com"); return new ApiInfo( "OSLC Api Documentation", "Api Documentation", "1.0", "urn:tos", contact, "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", new ArrayList()); } }

    修改扫描路径

    //修改扫描路径 @Bean public Docket docket(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() //配置扫描的方式RequestHandlerSelectors //basepackage .apis(RequestHandlerSelectors.basePackage("com.wildec.Controller")) .paths(PathSelectors.) .build(); }

    配置API文档的分组

    Processed: 0.012, SQL: 9