How do @Controller and @RestController differ? What are redirect, forward and Post/Redirect/Get?
Short answer
@RestController = @Controller + @ResponseBody: the return value is written straight into the body (JSON); with @Controller, the returned string is a view name. Post/Redirect/Get means redirecting to a GET after a POST, so F5 doesn't resubmit the form.
3 points to say:
@RestControllerreturns data;@Controllerreturns a view name (Thymeleaf, JSP).redirect:: 2 requests, URL changes;forward:: 1 internal request, URL stays.- PRG stops form resubmission on F5; a REST API returns
201 Created+Location, not a redirect.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.