@RestController marks a class whose controller actions return data directly in HTTP responses. It combines @Controller and @ResponseBody, so you do not need to repeat @ResponseBody on every action. section 10.2
Listing 10.3 Using the @RestController annotation to avoid code duplication.
@RestController #A
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "Hello!";
}
@GetMapping("/ciao")
public String ciao() {
return "Ciao!";
}
}A HelloController uses @RestController once for its /hello and /ciao actions, replacing repeated @ResponseBody annotations. section 10.2
Without @RestController or @ResponseBody, Spring’s dispatcher servlet assumes an action returns a view name and looks for that view. section 10.6


