闊歩インタフェースのドキュメント生成ツール

まず、パケットインタフェース依存ジャー

    <properties>
        <swagger-version>2.9.2</swagger-version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger-version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${swagger-version}</version>
        </dependency>
    </dependencies>

二つは、闊歩は、コンフィギュレーションクラスを起動する必要があります

package org.example.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.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;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .pathMapping("/")
                .select()
                .paths(PathSelectors.regex("/.*"))
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("接口文档")
                .contact(new Contact("charles","","[email protected]"))
                .description("Swagger生成的接口文档")
                .version("1.0.0.1")
                .build();
    }
}

第三には、パッケージが開始スキャンSpringbootは、コンフィギュレーション・クラスをスキャンする必要があります

 

スタート:

http://127.0.0.1:8888/swagger-ui.html#/springboot-get-test

公開された30元の記事 ウォン称賛7 ビュー4679

おすすめ

転載: blog.csdn.net/qq969887453/article/details/104088139