
[Spring] ResponseEntity란? [HTTP 응답을 생성할 때 매우 유용한 클래스]
·
▣ Framework/Spring🍃
- ResponseEntity란?ResponseEntity는 Spring에서 HTTP 응답을 생성할 때 매우 유용한 클래스이다. 상태 코드, 헤더, 본문을 자유롭게 조작할 수 있기 때문에 다양한 HTTP 응답을 세밀하게 제어할 수 있다.- 기본 사용법 // 기본적인 ResponseEntity 사용 예시ResponseEntity response = new ResponseEntity(body, HttpStatus.OK);- 주요 사용 예시들 1) 기본적인 응답 ResponseEntity.ok() : 상태 코드 200 OK와 함께 응답 본문 반환 @ResponseBody@PostMapping("/example")public ResponseEntity example() { // 정상적으로 처리된 응답 ..