MVC (Model-View-Controller) is a software design pattern that separates an application’s logic into three interconnected components: the Model, the View, and the Controller. This separation of concerns promotes modularity, reusability, and testability, making it a popular choice for web applications and other types of software development.
MVC architecture
In Model View Controller (MVC) architecture:
- Controller (Handles Requests)
- Acts as the middleman between Model and View
- Receives HTTP requests, processes input, and calls the appropriate model logic
- Passes data to the view (powered by different view technology) to render
- Model (Data & Business Logic)
- Represents the data (like a Java class: User, Product)
- Contains business logic and rules (e.g., calculating prices, validating input)
- Communicates with the database (via DAOs or repositories)
- View (User Interface)
- Responsible for displaying data to the client (i.e. browser)
- Usually built using HTML, JSP, Thymeleaf, or another templating engine
- Should not contain business logic
In traditional Servlet + Tomcat Java web configuration, if you want to create a controller, you will be using Servlets; when you want to create a view, you will be using JavaServer Pages (JSP); when you want to represent a model, you will use a simple Java class, which is also known as Plain Old Java Object (POJO).
Implement MVC with Spring Boot
We can built a MVC project with the help of Spring, which provides comprehensive support for building it and significantly reduce development time. There are two ways of doing it:
- Using normal Spring Framework (More configurations)
- Using Spring Boot (Easy handon)
Back to parent page