

<dependencies>
..... 아래 디펜던시를 여기에 삽입 .....
</dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<추가 했다면 ??>
Maven 프로젝트를 업데이트를 합니다.
하는 방법은 두 가지입니다. 둘 중 한가지 방법을 택하여 진행합니다.
1.pom.xml 우클릭 → Maven → Reload project 클릭


com.springboot.api_prac 아래 config 패키지 생성 후 SwaggerConfiguration 클래스 생성한다.

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.springboot.api_prac"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("Spring Boot Open API Test with Swagger")
.description("설명 부분입니다.")
.version("1.0.0")
.build();
}
}
@Configuration: 이 어노테이션은 이 클래스가 Spring의 구성 클래스임을 나타냅니다. Spring은 이 클래스를 구성 클래스로 인식하고 빈(bean)을 정의하는 데 사용합니다.@EnableSwagger2: Swagger를 활성화하는 어노테이션 입니다. 이 어노테이션이 지정된 클래스에서 Swagger 관련 설정이 이루어집니다.@Bean: 이 어노테이션은 Spring 빈(bean)을 정의할 때 사용됩니다. Docket 객체를 반환하는 api() 메서드를 정의하고 이 메서드의 반환값을 Spring 빈으로 등록합니다.http://localhost:8080/swagger-ui.html 로 접속합니다.
<접속 화면>

컨트롤러를 누르면 지금까지 우리가 만든 컨트롤러들이 전부 나옵니다.

기존 GetController에 @RequestParam을 활용하여 메서드의 세부내용을 설정 해봅시다.
이번에 만든 GET메서드를 수정해 봅시다.
<기존 getRequestParam1 메서드 >
@GetMapping(value = "/request1")
public String getRequestParam1(
@RequestParam String name,
@RequestParam String email,
@RequestParam String school){
return name+" \n"+email+" \n"+school;
}
<수정한 getRequestParam1 메서드 >
@ApiOperation (value = "GET 메서드 예제입니다.", notes = "@RequestParam을 활용한 GET Method 수정")
@GetMapping(value = "/request1")
public String getRequestParam1(
@ApiParam(value = "이름",required = true) @RequestParam String name,
@ApiParam(value = "이메일",required = true) @RequestParam String email,
@ApiParam(value = "회사",required = true) @RequestParam String school){
return name+" \n"+email+" \n"+school;
}
<실행 화면>


값을 입력후 [Execute]버튼을 누르면 다음과 같이 자동으로 완성된 요청 URL을 확인하고, 그에 대한 결과 값도 받을 수 있습니다.
