MVC Architectture:
Purpose of MVC architecture is to support loose coupling
between Model, View and Controller. It makes easier to maintain the code at
different levels.
View is the front end component, which can be understood by
browser. It can be plain HTML; JSP etc.It presents the model data to the viewer.
Model is the POJO (Plain Old Java Object), a java class with
attributes, getters and setters. It can also have some business logic.
Controller is the dispatcher of the requests to different services
to build model object. It passes that model
object data to View.
Spring MVC
Spring framework provides these features with its MVC libraries/framework.
DispatcherServlet is the front controller in spring framework.
So any request sent from browser will be handled by DispatcherServlet. We have
to provide the configuration to handle the request as per our needs.
@Controller
annotation can be used to declare a Controller. We have @RequestMapping
annotation to interpret the request URL and send it to required service
methods.
Controller methods call the service methods with request model object and prepares response model object to send it to View.
Controller methods call the service methods with request model object and prepares response model object to send it to View.
There are different View resolvers provided by spring to
render the output in particular type of view.