우선,

@Controller와 @RestController 둘 다 spring에서 controller를 지정하기 위한 어노테이션이다

 

 

@Controller

Spring MVC의 Controller

View 반환

 

<과정>

1) Client에서 보낸 요청은 DispatcherServlet을 거쳐 HandleMapping을 통해 Controller 찾고 요청 수행

2) Controller는 받은 요청을 처리하고 난 뒤 ViewName 반환

3) DispatcherServlet은 ViewReslver를 통해 ViewName에 해당하는 View를 찾아 사용자에게 반

 

<but Date 반환하고 싶을때>

ResponseEnity의 Body를 사용해야하는데, 이 때 @Controller와 함께 @ResponseBody 어노테이션 사용하면

JSON 형태의 데이터 반환 가능

ResponseEnity로 감싸서 객체 반

 

 

@RestController

RESTful웹 서비스의 Controller

간단하게 말하자면 @Controller + @RequestBody 합쳐진 어노테이션

JSON 형태의 객체 데이터 반환

ResponseEntity로 감싸서 반환

 

 

+ Recent posts