Spring Boot Http 응답 - HTTP API, Message Body에 직접 입력

목차

Spring Boot Http 응답 - HTTP API, Message Body에 직접 입력

@GetMapping("/response-body-string-v1")
public void responseBodyV1(HttpServletResponse response) throws IOException {
response.getWriter().write("ok");
}
@GetMapping("/response-body-string-v2")
public ResponseEntity<String> responseBodyV2(HttpServletResponse response) {
return new ResponseEntity<>("ok", HttpStatus.OK);
}
@ResponseBody
@GetMapping("/response-body-string-v3")
public String responseBodyV3(HttpServletResponse response) {
return "ok";
}
@GetMapping("/response-body-json-v1")
public ResponseEntity<HelloData> responseBodyJsonV1() {
HelloData helloData = new HelloData();
helloData.setUsername("userA");
helloData.setAge(20);

return new ResponseEntity<>(helloData, HttpStatus.OK);
}
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@GetMapping("/response-body-json-v1")
public HelloData responseBodyJsonV2() {
HelloData helloData = new HelloData();
helloData.setUsername("userA");
helloData.setAge(20);

return helloData;
}
Share