Spring MVC Pattern With Dispatcher Servlet
Spring MVC Pattern With Dispatcher Servlet
Model: Represents the application's data or business logic. It manages the data and
interacts with the database.
View: Displays the data and is the UI layer of the application. It interacts with the model
and shows relevant information to the user.
Controller: Acts as an intermediary between the Model and View. It processes user
inputs and returns the appropriate response after interacting with the model.
Architecture:
1. Client (Browser or REST Client):
The client interacts with the server by sending HTTP requests. These can be GET, POST,
PUT, DELETE, etc., depending on the operation.
2. Controller Layer:
This is the entry point of the application for client requests.
Controllers are annotated with @Controller or @RestController and handle HTTP
requests using methods annotated with @RequestMapping, @GetMapping,
@PostMapping, etc.
The controller processes the incoming request, invokes services, and prepares the
appropriate response (HTML, JSON, XML).
3. Service Layer:
This layer contains the business logic of the application. It's responsible for processing
data and implementing business rules.
The service methods are usually called by the controller.
Services are defined using the @Service annotation.
Models can be simple POJOs (Plain Old Java Objects) with attributes and methods that
represent the data and state of the application.
Models interact with the database via the repository layer.
6. View Layer:
The view is responsible for displaying the data returned by the controller to the user.
In Spring Boot, this can be implemented using Thymeleaf, JSP, FreeMarker, or any front-
end framework like Angular, React (if you're using a REST API).
The view takes the model data and renders it into a format appropriate for the client
(HTML for web pages, JSON for REST APIs).
• Once the view is rendered, the DispatcherServlet returns the response (HTML,
JSON, etc.) to the client.