MVC · Model–View–Controller
Spring Concepts / MVC · Model–View–Controller
MVC separates application data, presentation, and HTTP request handling.
Understand the idea
The Model carries the data a view needs. The View renders that data as HTML. The Controller accepts a request, asks the service to perform an operation, and chooses the view and model attributes. Spring MVC implements this pattern around DispatcherServlet. For a JSON API, controllers use the same web infrastructure but return data through message converters instead of rendering a template.
A concrete example
GET /todos
→ TodoController.list(model)
→ service.list()
→ model.addAttribute("todos", tasks)
→ return "list"
→ Thymeleaf renders list.htmlIn the application
In Manual 01, TodoController handles routes, Model contains todos, and templates/list.html is the view. TodoService and TodoRepository handle business operations and database access behind the controller.
A controller should not contain HTML generation or database credentials. Also, the MVC Model is not necessarily the same object as a MongoDB document.
Detailed walkthrough: Trace a Spring MVC request →