swagger2 실제 전투 : springboot swagger2와 실제 전투, swagger2 입문 튜토리얼

머리말

API 인터페이스 생성을위한 강력한 도구 인 swagger2는 프런트 엔드 및 백 엔드 디버깅 비용을 크게 향상시킵니다. 백엔드 개발자는 인터페이스 문서의 조합에주의를 기울일 필요가 없으며 인터페이스 단어로 친숙한 방식으로 표현 될 수 있습니다.

실제 전투

  1. pom.xml 파일을 jar 패키지로 가져옵니다.
        <!-- 集成Swagger2接口测试工具(类似于postman) -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
        </dependency>
  1. springboot의 기본 클래스를 시작하려면 다음 주석을 추가하십시오.
//开启对swagger的支持
@EnableSwagger2
  1. swagger2에 대한 새 구성 클래스를 만듭니다.
package com.plugs.swagger;

import org.springframework.context.annotation.Bean;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

public class Swagger2Config {
    
    

	@Bean
	public Docket createRestApi() {
    
    
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(apiInfo())
				.select()
				.paths(PathSelectors.any())
				.build();
	}

	private ApiInfo apiInfo() {
    
    
		return new ApiInfoBuilder()
				.title("springboot利用swagger构建api文档")
				.description("")
				.termsOfServiceUrl("")
				.version("1.0")
				.build();
	}

}
  1. 방문 : ip : port / project name / swagger-ui.html
    여기에 사진 설명 삽입

  2. 전체 소스 코드 주소 얻기 : https://download.csdn.net/download/penggerhe/11670196

  3. 공식 계정을 팔로우하고 무료로 받으세요 :
    여기에 사진 설명 삽입

추천

출처blog.csdn.net/penggerhe/article/details/108337670