整合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();
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章