TIL

Spring Boot MVC Controller @Controller 와 @RestController

everyday-spring 2024. 8. 12. 14:12

@RestController를 사용하면 해당 클래스의 모든 Method에 @ResponseBody Annotation이 부여된다

@Controller의 클래스에서 내부 Method에 @ResponseBody가 붙어 있는 것과 같다

 

Controller HTTP Response
@ResponseBody Return Type Return Value Header Body
X String "{View name}" Content-Type: text/html View (HTML)의 text 내용
타임리프 기준
/templates/{View name}.html
"redirect:/{redirect URL}" Location:{Host URL}/{redirect URL} X
O String "{Text}" Content-Type:text/html "{Text}"
String 외 Java 객체 Content-Type:applicaion/json JSON
스프링이 변환해줌
(Java 객체 to JSON)

 

 

+추가적으로 실습시에 구분이 어려웠던 Annotation

@PathVariable

->URI 변수 처리

@RequestBody

->JSON 처리

'TIL' 카테고리의 다른 글

SpringBoot mvc Repository  (0) 2024.08.14
프로그래머스 코딩테스트연습 133499 '옹알이 (2)'  (0) 2024.08.13
240809  (0) 2024.08.09
240808  (0) 2024.08.08
240807  (0) 2024.08.07