학습용 공간

JAVA Spring 2020.08.31 댓글 개 starmk95

JAVA Spring) ResponseEntity란 무엇인가?

# ResponseEntity

- ResponseEntity는 RESTful API에서 return type으로써 사용된다.

- 일반적인 MVC의 Controller는 View를 사용하지만, RESTful은 객체를 반환하면 이를 JSON 형식으로 직접 HTTP Body에 넣어준다. (@ResponseBody와 유사한 가능을 한다.)

- ResponseEntity는 HTTP의 Header, Body, Status Code를 제어할 수 있다. (ResponseBody보다 세밀한 작업 가능)

- ResponseEntity를 return type으로 지정하면 JSON 또는 XML 형식으로 결과를 내준다.

- ReponseEntity는 HttpEntity를 상속받음으로써 HTTP Header와 Body를 가질 수 있다.

 

# ResponseEntity 클래스의 정보

docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/ResponseEntity.html

 

ResponseEntity (Spring Framework 5.2.8.RELEASE API)

Extension of HttpEntity that adds a HttpStatus status code. Used in RestTemplate as well @Controller methods. In RestTemplate, this class is returned by getForEntity() and exchange(): ResponseEntity entity = template.getForEntity("https://example.com", Str

docs.spring.io