The role of a controller in Spring MVC
In Spring MVC, controller methods are the final destination point that a web request can reach. After being invoked, the controller method starts to process the web request by interacting with the service layer to complete the work that needs to be done. Usually, the service layer executes some business operations on domain objects and calls the persistence layer to update the domain objects. After the processing has been completed by the service layer object, the controller is responsible for updating and building up the model
object and chooses a view for the user to see next as a response.
Remember that Spring MVC always keeps the controllers unaware of any view technology used. That's why the controller returns only a logical view name; later, DispatcherServlet
consults with ViewResolver
to find out the exact view to be rendered. According to the controller, Model
is a collection of arbitrary objects and View
is specified with a logical name...