Spring Boot Swagger 2 사용 방법 프로 세 스 분석

2069 단어 SpringBootSwagger
1.Swagger 2 의존 추가

<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger2</artifactId>
  <version>2.2.2</version>
</dependency>
<dependency>
   <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger-ui</artifactId>
  <version>2.2.2</version>
</dependency>
2 설정 클래스

@Configuration
@EnableSwagger2
public class Swagger2 {
  @Bean
  public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo())
        .select()
        .apis(RequestHandlerSelectors.basePackage("com.bs.swaggertest.controller"))
        .paths(PathSelectors.any())
        .build();
  }
  private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
        .title("          ")
        .description("        ")
        .contact("   ")
        .version("1.0")
        .build();
  }
}
3.문서 내용 추가

@RestController
@RequestMapping(value="/users")
public class UserController {
  @ApiOperation(value="    ", notes="  url id       ")
  @ApiImplicitParam(name = "id", value = "  ID", required = true, dataType = "String")
  @RequestMapping(value="/{id}", method=RequestMethod.DELETE)
  public String deleteUser(@PathVariable String id) {
    return "success";
  }
}
4.테스트
http://localhost:8080/swagger-ui.html



이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기