整合Swagger2文檔Api

1、引入依賴

<!-- swagger2 配置 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.4.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.4.0</version>
        </dependency>
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>swagger-bootstrap-ui</artifactId>
            <version>1.6</version>
        </dependency>

2、Api配置

@Configuration
@EnableSwagger2
public class Swagger2 {


    // 配置Swagger2核心配置 docket
    @Bean
    public Docket createRestApi() {

        return new Docket(DocumentationType.SWAGGER_2)  // 指定Api類型爲swagger2
                .apiInfo(apiInfo())                 // 用於定義Api文檔彙總信息
                .select().apis(RequestHandlerSelectors.basePackage("com.sh.controller"))  // 指定Controller包
                .paths(PathSelectors.any())         // 所有Controller
                .build();
    }


    private ApiInfo apiInfo() {

        return new ApiInfoBuilder()
                .title("天天喫貨 電商平臺接口Api")      // 文檔頁標題
                .contact(new Contact("lee",
                        "https://www.sh.com",
                        "[email protected]"))   // 聯繫人信息
                .description("專爲天天喫貨提供的Api文檔")       // 詳細信息
                .version("1.0.0")                              // 版本號
                .termsOfServiceUrl("https://www.sh.com")       // 網站地址
                .build();
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章