โ
@ResponseStatus
์๋ต์ผ๋ก ๋ณด๋ผ ๋ฐ์ดํฐ์ HttpStatus๋ฅผ ๋ช ์ํด์ฃผ๋ ๋ฐฉ๋ฒ์ด๋ค. ์ปจํธ๋กค๋ฌ์์ Body ๋ฐ์ดํฐ๋ง ๋ฐํํ๋ ๊ฒฝ์ฐ HttpStatus๋ฅผ ๋ช ์ํ๊ธฐ ์ํด ์ฌ์ฉํ๋ค.
@ResponseStatus(HttpStatus.OK)
@GetMapping("/article")
public ArticleListDto getArticles(SelectArticlesQuery query) {
ArticleListDto articleListDto = articleService.getArticleList(query);
return articleListDto;
}ResponseEntity
์คํ๋ง์์ HTTP ์์ฒญ ํน์ ์๋ต์ ๋ํ๋ด๊ธฐ ์ํด ์ ๊ณตํ๋ HttpEntity๋ผ๋ ํด๋์ค๊ฐ ์กด์ฌํ๋ฉฐ, HttpEntity๋ HttpHeader์ HttpBody๋ฅผ ํฌํจํ๋ ํด๋์ค์ด๋ค.
์ด๋ฌํ HttpEntity๋ฅผ ์์ํ์ฌ ์ถ๊ฐ์ ์ผ๋ก HttpStatus ์์ฑ์ ๋ ๊ฐ์ง๋ ํด๋์ค๊ฐ RequestEntity, ResponseEntity ํด๋์ค์ด๋ค.
์ ๋ค๋ฆญ์ผ๋ก ์ ์ธ๋์ด์์ผ๋ฉฐ ํด๋น ๋ถ๋ถ์ HttpBody ํ์ ์ ๋ํ๋ธ๋ค.
@GetMapping("/article")
public ResponseEntity<ArticleListDto> getArticles(SelectArticlesQuery query) {
ArticleListDto articleListDto = articleService.getArticleList(query);
return ResponseEntity.ok(response);
}@ResponseStatus์ ๋จ์
@ResponseStatus๋ ๋จ ํ๋์ ์๋ต ์ํ ์ฝ๋๋ฅผ ์ง์ ํ๋ ๊ฒ ์ธ์ ๋ค๋ฅธ ์์ ์ด ๋ถ๊ฐ๋ฅํ๋ค๋ ๊ฒ์ด ๊ฐ์ฅ ํฐ ๋จ์ ์ด๋ค. ๋ฐ๋ผ์ ๋ณดํต @ResponseStatus๋ ์๋ฌ ํธ๋ค๋ง ์ปจํธ๋กค๋ฌ์์ ์ฃผ๋ก ์ฌ์ฉํ๊ณ , ์ค์ ์๋น์ค๋ฅผ ๋ด๋นํ๋ ์ปจํธ๋กค๋ฌ์์๋ ์ฌ์ฉํ๊ธฐ์ ๋ถํธํ๋ค.
ResponseEntity์ ๊ฒฝ์ฐ ํ์ํ๋ค๋ฉด, ์ปจํธ๋กค๋ฌ ๋ฉ์๋ ๋ด๋ถ์์ ์ค๋ฅ ์ํ ์ฝ๋๋ฅผ ์ง์ ํ์ฌ ์ค๋ฅ๋ฅผ ๋ณด๋ผ ์ ์๋ค. ๋ํ Header์ ๋ํ ์ค์ ๋ ๊ฐ๋ฅํ๋ค. ๋ฐ๋ผ์ @ResponseStatus์ ๋นํด ์ ์ฐ์ฑ์ด ์ข๋ค.