https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#mvc-ann-responsebody
Web on Servlet Stack
Spring Web MVC is the original web framework built on the Servlet API and has been included in the Spring Framework from the very beginning. The formal name, “Spring Web MVC,” comes from the name of its source module (spring-webmvc), but it is more com
docs.spring.io
@Controller 클래스의 @RequestMapping이 붙은 메소드가 뷰를 리턴하지만
HttpMessageConverter를 통해 직렬화된 데이터를 응답 바디로 리턴할 수 있다. @ResponseBody를 클래스 레벨에 선언하면 @RestController를 사용한것과 같은 효과를 가진다.
@RequestMapping("/mapping")
@Controller
public class RequestMappingController {
@ResponseBody
@RequestMapping(value = "body")
public Member getMember() {
Member member = new Member();
member.setId("hong");
member.setName("홍길동");
return member;
}
}
요청 URL : http://localhost:8080/mapping/body
{"id":"hong","name":"홍길동"}
Spring MVC @ResponseEntity (0) | 2022.05.31 |
---|---|
Spring MVC @RequestBody (0) | 2022.05.26 |
Spring MVC @ModelAttribute (매개변수 레벨) (0) | 2022.05.25 |
댓글 영역