ResponseEntity<Void>
์ฌ์ฉ โ ์๋กญ๊ฒ ์๊ฒ ๋ ์ void
๋ก ์ฒ๋ฆฌํด๋ ๋ฌธ์ ๊ฐ ์๋ค:
@PostMapping
public void createDiary(@RequestBody DiaryRequestDto requestDto) {
diaryService.saveDiary(requestDto);
}
๋ฌธ์ ์ : ํด๋ผ์ด์ธํธ๋ ์๋ฒ ์๋ต์ ๋ฐ์๋
์ ํํ ์ด๋ค ์ํ์ฝ๋๊ฐ ๋ฐํ๋๋์ง ์๊ธฐ ์ด๋ ต๋ค.
ResponseEntity
์ฌ์ฉ
@PostMapping
public ResponseEntity<Void> createDiary(@RequestBody DiaryRequestDto requestDto) {
diaryService.saveDiary(requestDto);
return ResponseEntity.ok().build(); // 200 OK ๋ฐํ
}
ResponseEntity
๋ฅผ ์ฌ์ฉํ๋ฉด ์๋ต ์ฝ๋์ ๋ฉ์์ง๋ฅผ ๋ช
์์ ์ผ๋ก ์ ์ด ๊ฐ๋ฅํ๋ค.200 OK
, ์คํจ ์ 400 Bad Request
, 403 Forbidden
, 500 Internal Server Error
๋ฑ์ ์ฝ๊ฒ ๋ฐํํ ์ ์์.ํญ๋ชฉ | void ๋ฐฉ์ |
ResponseEntity ๋ฐฉ์ |
---|---|---|
์ํ ์ฝ๋ ์ค์ | โ ๋ช ์ ๋ถ๊ฐ (๊ธฐ๋ณธ๊ฐ ์ฌ์ฉ) | โ ๋ช ์ ๊ฐ๋ฅ |
๋ฉ์์ง ์ ๋ฌ | โ ๋ถํธ | โ ์ ์ฐํ๊ฒ ์ฒ๋ฆฌ ๊ฐ๋ฅ |
์ค๋ฌด ํ์ฉ๋ | ๋ฎ์ (๋จ์ ํ ์คํธ์ฉ) | ๋์ (ํ์ค ์๋ต ์ฒ๋ฆฌ) |
์ค๋ฌด์์๋ ์๋ฌ ์ฒ๋ฆฌ, ๋ช ํํ ์ํ ๋ฐํ, ์๋ต ๋ฉ์์ง ์ ์ด๊ฐ ์ค์ํ๋ฏ๋ก
ResponseEntity
๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ํจ์ฌ ์ ๋ฆฌํ๋ค๋ ๊ฒ์ ์๊ฒ ๋์๋ค.