Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Iterator
- tomcat
- ip체크
- String
- 정해진기간동안
- swagger
- 톰캣
- 최대최소
- Timeout
- java
- Interceptor
- CentOS
- session
- Spring
- vi
- new
- indexof
- 배열
- SAMBA
- 새글
- login
- 접속권한
- Linux
- Log4j
- 권한부여
- new아이콘
- 자바
- springboot
- lombok
Archives
- Today
- Total
Cheat Sheet
#SpringBoot #Swagger 본문
spring fox(x), spring doc(o)
[ build.gradle 추가 ]
implementation 'org.springdoc:springdoc-openapi-ui:1.6.6'
[ application.properties 추가 ]
springdoc.packages-to-scan=org.zerock.corp_1.controller
springdoc.paths-to-exclude=/notes/*
springdoc.default-consumes-media-type= media-type: application/json;charset=UTF-8
springdoc.default-produces-media-type= application/json;charset=UTF-8
springdoc.swagger-ui.path=/
springdoc.swagger-ui.disable-swagger-default-url=true
springdoc.swagger-ui.display-request-duration=true
springdoc.swagger-ui.operations-sorter=alpha
[ SwaggerConfig.java 생성 ]
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI openAPI() {
return new OpenAPI()
.components(new Components())
.info(apiInfo());
}
private Info apiInfo() {
return new Info()
.title("Springdoc 테스트")
.description("Springdoc을 사용한 Swagger UI 테스트")
.version("1.0.0");
}
}
application.properties에서 설정한
springdoc.packages-to-scan=org.zerock.corp_1.controller
패키지 경로 하위의 controller에 설정한 api를 swagger문서로 확인가능
[ 어쩌고저쩌고Controller.java ]
@RestController
@Log4j2
@RequestMapping("/api/corp/")
@RequiredArgsConstructor
public class CorpController {
@Operation(summary = "cm_corp > list", description = "기업 리스트")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ResponseEntity.class))),
@ApiResponse(responseCode = "400", description = "BAD REQUEST"),
@ApiResponse(responseCode = "404", description = "NOT FOUND"),
@ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR")
})
@Parameters({
@Parameter(name = "cmpn_id", description = "회사 아이디", example = "CP0001"),
@Parameter(name = "brnc_id", description = "지사 아이디", example = "BR0001"),
@Parameter(name = "dprt_id", description = "부서 아이디", example = "DP0001"),
@Parameter(name = "mbr_id", description = "회원 아이디", example = "ㅁㅁㅁㅁ"),
@Parameter(name = "currentPage", description = "현재 페이지", example = "30"),
@Parameter(name = "recordSize", description = "페이지 크기", example = "10"),
@Parameter(name = "sort", description = "정렬", example = "0")
})
// 기업 리스트
@PostMapping("list")
public ResponseEntity<Object> getCorpList(@RequestBody HashMap<String, Object> paramMap){
log.info("-----------POST /api/corp/list-------------------------------");
Object obj = corpService.getCorpList(paramMap);
return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.SELECT_SUCCESS, obj), HttpStatus.OK);
}
}
여기까지 설정 후
http://localhost:8081/swagger-ui/index.html#/
위 URL로 들어가면 확인가능
'Back End > 프레임워크' 카테고리의 다른 글
#SpringBoot #lombok (0) | 2023.09.08 |
---|---|
#Spring Boot #log4j (0) | 2023.09.08 |
#Interceptor #login #spring (0) | 2019.04.05 |
#HttpServletRequest # RequestParam #데이터객체 #ModelAttribute #Model (0) | 2018.08.29 |
#CKEditor #이미지업로드 (0) | 2018.08.08 |