본문 바로가기
자바의 봄(Spring)/자바와 스프링 공부하기

[Spring] ResponseBody 어노테이션의 작동원리

by 종안이 2023. 1. 16.

ResponseBody 어노테이션의 작동원리

 

 

1. ResponseBody 어노테이션이 붙은 경우 

1. 웹 브라우져에서 해당 주소로 요청이 발생하면 (hello-api)  helloController에서 

  hello객체를 리턴해주게 된다. 

@ResponseBody가 붙지않은 경우에는 ViewResolver가 작동하지만 

지금은 ResponseBody 어노테이션이 붙어있으니 HttpMessageConverter가 작동하게 된다.

 

여기서 두가지 메서드가 존재하는데 

일반 문자열의 경우에는 StringConverter가 작동하게 되고 , 

JSON의 경우에는 JsonConverter가 작동하게 된다.

 

 

 

댓글