springframework.http.ResponseEntity
๐ ResponseEntity ๊ฐ์ ๐ ๋ค๋ฅธ ๋ฐฉ๋ฒ๊ณผ ๋น๊ต What? Why? ์คํ๋ง 3 ๋ฒ์ ๋ถํฐ ๋์ ๋์์ผ๋ฉฐ, ์คํ๋ง MVC์์ HTTP ์๋ต์ ๋ค๋ฃจ๋ ์ฃผ์ ํด๋์ค ์ค ํ๋์ด๋ค. HTTP ์๋ต์ ์ ์ฒด ๋ด์ฉ์ ์ ์ดํ ์ ์๋๋ก ํด์ฃผ๋ฉฐ, ์ด๋ฅผ ํตํด ๋ค์๊ณผ ๊ฐ์ ์์๋ค์ ์ค์ ํ ์ ์๋ค. ์ํ ์ฝ๋ (HTTP Status Code) : 200 OK, 404 Not Found, 500 Internal Server Error ๋ฑ ํค๋ (Headers) : ์๋ต ํค๋์ ํน์ ๊ฐ์ ์ถ๊ฐ/์์ ๋ณธ๋ฌธ (Body) : ์ค์ ๋ก ํด๋ผ์ด์ธํธ์๊ฒ ์ ๋ฌ๋ ๋ฐ์ดํฐ @GetMapping("/example") public ResponseEntity<String> getExample() { String body = "Hello, World!"; HttpHeaders headers = new HttpHeaders(); headers.add("Custom-Header", "CustomValue"); return new ResponseEntity<>(body, headers, HttpStatus.OK); } @ResponseBody ๊ฐ์ฒด๋ฅผ ์ง๋ ฌํํ์ฌ ๋ฐํํ๋ ์ด๋ ธํ ์ด์ ์ผ๋ก, ์ด๊ฒ๋ง ์ฌ์ฉํ ๊ฒฝ์ฐ ํค๋๋ฅผ ์ ์ฐํ๊ฒ ์ค์ ํ ์ ์๋ค. @ResopnseStatus๋ฅผ ์ฌ์ฉํ์ฌ ํค๋๋ฅผ ์ค์ ํ ์ ์์ง๋ง, ์ด๋ ธํ ์ด์ ์ ๋ณ๋๋ก ์ถ๊ฐํด์ผํ๋ ๋จ์ ์ด ์๋ค. ...