Swagger2 学习

特点

1.自动生成API的工具
2.开源

结果展示

展示.png

接口.png

使用

pom依赖


      
            io.springfox
            springfox-swagger2
            2.9.2
        

        
        
            io.springfox
            springfox-swagger-ui
            2.9.2
        

Swagger 配置类

package com.bcm.task.config;

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.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2 配置类
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {


    /**
     * Docket实例
     * @return
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.bcm.task.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * Swagger apiInfo
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("API文档")
                .contact(new Contact("信息部", "http://172.38.9.32:9999", "[email protected]"))
                .version("1.0")
                .description("Api 描述")
                .build();
    }
}

启动访问查看效果

http://localhost:8080/swagger-ui.html

后期在做补充

你可能感兴趣的:(Swagger2 学习)