ResponseEntity는 공식에서 이렇게 설명한다.
Extension of HttpEntity that adds an HttpStatusCode status code.
말 그대로 해석해보자면 HttpStatusCode 상태 코드를 추가하는 HttpEntity의 확장이라는 소리다.
이때 HttpEntity란 무엇이냐!!
HttpEntity :
header와 body로 구성된 HTTP요청, 혹은 응답엔티티를 표현한다.
보면 ResponseEntity는 HttpEntity를 상속받았음을 알 수 있다.
HttpStatusCode : HTTP 상태코드의 열겨형이다. (enum)
인터넷을 하다보면 가끔 404 에러를 본 적이 있을텐데, 이런 http 상태에 대한 코드들이 열겨되어있는 enum이 HttpStatusCode이다.
보통 많이 사용하는건
HttpStatus.OK (200)
HttpStatus.NOT_FOUND(404) 인것 같다.
나는 코드에서 아래와 같이 사용하였다.
"success" 라는 값과, HttpStatus.OK라는 상태코드 값을 전해준다.
@DeleteMapping("/{rno}")
public ResponseEntity<String> remove(@PathVariable("rno") Long rno){
log.info("RNO : " + rno);
replyService.remove(rno);
return new ResponseEntity<>("success",HttpStatus.OK);
}
이를 받는 쪽에서는
success: function(result){
console.log("result: " + result);
이런식으로 result 값으로 가져와 콘솔창에 띄워보면
result : success 라고 나오는걸 확인할 수 있다.
'study > backend' 카테고리의 다른 글
[TIL] 13 엔티티 매핑 (0) | 2023.06.26 |
---|---|
[TIL]11 JPA - 영속성 (0) | 2023.06.23 |
[TIL] 10 H2 db 설치하기 (0) | 2023.06.22 |
[TIL] 08 @ManyToOne, @OneToMany.. (0) | 2023.06.20 |
[TIL] 07 @RequestMapping, @Builder (0) | 2023.06.19 |