Spring Boot
@RestController
seoca
2019. 2. 10. 08:07
@Controller and @RestController
1 2 3 | @Controller @ResponseBody public class MyController{} | cs |
@Controller 일때는 @ResponseBody 까지 명시해줘야 하지만
1 2 | @RestController public class MyRestController{} | cs |
@RestController 는 @ ResponseBody가 이미 자동적으로 적용이 되기 때문에 따로 적어주지 않아도 사용할 수 있다.
@ResponseBody
- Java객체를 http응답객체로 전송할 수 있다.
- Serialization(converting Object to JSON)
@RequestBody
- 요청이 온 data(JSON or XML) 를 바로 class 나 model 로 mapping 해주는 annotation
- Deserialization(converting JSON to Object)
1 | public ResponseEntity saveTravel(@RequestBody @Valid TravelDto travelDto, Errors errors) | cs |