ResponseEntity

  • status code 지정가능
  • header 지정가능
  • body 를 여러가지 type으로 지정가능 : Map, 일반 VO
@GetMapping("/example")
public ResponseEntity<Map<String, Object>> response() {
    Map<String, Object> body = new HashMap<>();
    body.put("param", "value");
    body.put("param2", "value2");

    HttpHeaders headers = new HttpHeaders();
    headers.add("param", "value");
    headers.add("param2", "value2");

    return ResponseEntity
        .status(HttpStatus.OK) // 워낙 많이 쓰여서 Facdae Pattern인 .ok() 로도 대체 가능
        .headers(headers)
        .contentType(MediaType.APPLICATION_JSON)
        .body(body);
}
참고

results matching ""

    No results matching ""