๐ํ๊ฒฝ
IntelliJ Ultimate
Java 17
Spring boot 3.2.3
Gradle - Groovy
Dependencies:
Spring Web
Thymeleaf
Spring Data JPA
lombok
MariaDB 10.11
Spring Dev tool
์ด์ ๊ธ์์ springfox ๋์ springdoc์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด์๋ค. springfox์ springdoc๋ ์ฌ์ฉ ๋ฐฉ๋ฒ์ด ์กฐ๊ธ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ์ฐจ๊ทผ์ฐจ๊ทผ ๋ฐ๋ผ๊ฐ๋ ์ฑ ์ด๋ ๊ฐ์์์ springfox๋ฅผ ์ฌ์ฉํ๋ค๋ฉด ์งํ์ด ์ด๋ ค์ธ ์ ์๋ค. ๋ ์ญ์ ๊ทธ ๋ฌธ์ ๋ฅผ ๊ฒช์๊ธฐ ๋๋ฌธ์ ํด๋น ๊ธ์ ์์ฑํ๋ค.
๋ด๊ฐ ์ฐธ๊ณ ํ ์ฑ (์๋ฐ ์น ๊ฐ๋ฐ ์ํฌ๋ถ)์์๋ REST ๋ฐฉ์์ผ๋ก ๋๊ธ์ ์ฒ๋ฆฌํ๊ธฐ ์ํด `ReplyDTO`๋ฅผ ๋ง๋ค๊ณ , JSON์ผ๋ก swagger๋ฅผ ํตํด ๋ฐ์ดํฐ๋ฅผ ์ ์กํ ๋ค `ReplyController`์์ ์ด๋ฅผ ์ฒ๋ฆฌํ๋ ๋ฐฉ์์ ์ฌ์ฉํ๋ค.
springfox๋ก ์์ฑ๋ `ReplyController` ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ๋ค.
package org.zerock.b02.controller;
import io.swagger.annotations.ApiOpertaion;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.zerock.b02.dto.ReplyDTO;
import java.util.Map;
@Controller
@RequestMapping("/replies")
@Slf4j
public class replyController {
@ApiOperation(value = "Replies Post" notes = "POST ๋ฐฉ์์ผ๋ก ๋๊ธ ๋ฑ๋ก")
@PostMapping(value = "/", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Long>> register(@RequestBody ReplyDTO replyDTO){
log.info("replyDTO........" + replyDTO);
Map<String, Long> resultMap = Map.of("rno", 111L);
return ResponseEntity.ok(resultMap);
}
}
`@ApiOperation` ์ ๋ํ ์ด์ ์ด ์ฌ์ฉ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค. springdoc์์๋ `@ApiOperation` ๋์ `@Operation`์ ์ฌ์ฉํ๋ฏ๋ก 20๋ฒ์งธ ์ค์ ์ ๋ํ ์ด์ ๋ง ๋ค์๊ณผ ๊ฐ์ด ์์ ํด์ค๋ค.
@Operation(summary = "reply POST", description = "POST ๋ฐฉ์์ผ๋ก ๋๊ธ ๋ฑ๋ก")
http://localhost:8080/swagger-ui/index.html์ ์ ์ํด๋ณด๋ฉด ์์ ๊ฐ์ด ์ ๋ค์ด์จ ๊ฒ์ ํ์ธํ ์ ์๋ค.
`Try it out`์ ๋๋ฅด๊ณ excuteํ๋ฉด ๋ค์๊ณผ ๊ฐ์ ๋ก๊ทธ๋ฅผ ํ์ธํ ์ ์๋ค.
2024-03-13T22:59:30.791+09:00 INFO 87464 --- [b02] [nio-8080-exec-4] o.springdoc.api.AbstractOpenApiResource : Init duration for springdoc-openapi is: 115 ms
2024-03-13T23:12:17.761+09:00 INFO 87464 --- [b02] [nio-8080-exec-6] o.springdoc.api.AbstractOpenApiResource : Init duration for springdoc-openapi is: 43 ms
2024-03-13T23:18:12.240+09:00 INFO 87464 --- [b02] [nio-8080-exec-2] o.zerock.b02.controller.replyController : replyDTO........ReplyDTO(rno=0, bno=0, replyText=string, regData=2024-03-13T14:17:56.754, modDate=2024-03-13T14:17:56.754)
'Java > Spring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SpringBoot/JPA] deleteById์ ์๋ชป๋ ๊ฐ์ ๋ฃ์ด๋ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ง ์์ (0) | 2024.03.14 |
---|---|
[Spring] Mac M1 ์คํ๋ง๋ถํธ ์คํ ์ Port 8080 is already in use (0) | 2024.03.13 |
[SpringBoot] Swagger ์ฌ์ฉ ์ ์ค๋ฅ (0) | 2024.03.13 |
[SpringBoot/JPA] ๊ฒ์์ ํฌํจํ ํ์ด์ง ์ฒ๋ฆฌ DTO (0) | 2024.03.13 |
[SpringBoot/JPA] ModelMapper๋ก Entity์ DTO ๋ณํํ๊ธฐ (0) | 2024.03.13 |