SpringBoot集成 Swagger

1. 新建項目

在這裏插入圖片描述在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

2. 導入相關依賴
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>

在這裏插入圖片描述

3. 編寫一個示例程序

在這裏插入圖片描述

4. 編寫 Swagger配置

在這裏插入圖片描述

5. 測試運行

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

6. 配置 Swagger
@Configuration
@EnableSwagger2  // 開啓 Swagger2
public class SwaggerConfig {

    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
    }

    public ApiInfo apiInfo(){
        Contact contact = new Contact("cxx", "#", "[email protected]");

        return new ApiInfo(
                "Swagger API 文檔",
                "略",
                "1.0",
                "#",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList()
        );
    }
}

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章