A model is not a database, it is not a repository, not an entity. A model is an abstraction containing all the data that needs to be displayed. And each View has its own model. You can think of Model as a container for data between Controller and View .
The Spring model uses the ModelMap parameter of the controller method.
Controller - prepares the Model to pass its View . If the model is fairly simple, the Controller can do this on its own.
But most models contain a lot of data. It can be several objects from the database, data from the configuration, etc. In this case, the controller uses the lower level: Service , Repository . All of them help ontroller build a model for the View .
upd: The purpose of the Controller is to connect View and Model . Controller creates and populates the Model , then selects the View and passes that created Model to the View . The way Model and View get connected.
Spring controllers have Controller and RestController .
View - the end point at which the data from the Model (transmitted from the Controller ) will be displayed to the user. But another View role is to receive commands from the user and pass it to the Controller .
In Spring, this can be a view of any viewer: JSP , Freemaker , Thymeleaf .
Note: Normally, the Controller does not use the Repository directly. Controller traditionally works with Service , and Service uses Repository to retrieve data from the database. So, the relationships are as follows: View <- Controller β Service β Repository
source share