[Spring Boot] ResponseEntity 클래스

hameee·2023년 12월 13일
0

Spring Boot

목록 보기
7/20
post-thumbnail

📍 ResponseEntity

  • 컨트롤러 메소드의 결과를 클라이언트에게 반환하기 위해 사용한다.
  • HTTP 응답의 상태 코드를 지정할 수 있다.
package com.example.lesson01;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/lesson01/ex01")
@RestController
public class Lesson01Ex01RestController {
	
	@RequestMapping("/1")
	public ResponseEntity<String> ex01_1() {
		return new ResponseEntity<>("hello world", HttpStatus.INTERNAL_SERVER_ERROR); // ⭐️ 500 error
	}
	
}

References

🔗 https://www.rfc-editor.org/rfc/rfc9110.html#name-status-codes

0개의 댓글