Spring Controllers and Views


Spring Controllers and Views

A single object or a group of objects might be considered data. A controller is where an application's business logic is stored, and the @Controller annotation is used to designate the class as the controller in this case. A view is a representation of the given data in a particular format.

Model-View-Controller (MVC) architecture and optimal components are provided with the Spring Web MVC framework, which can create flexible and freely connected web applications. The MVC pattern separates the various parts of an application (input logic, business logic, and user interface logic) while maintaining a loose connection between them.

  • The Model encompasses the application data and will, in most cases, be made up of POJO.
  • The View is in charge of displaying the model data, and it produces HTML output that the client's browser can understand.
  • The Controller handles user requests and creates a suitable model, which is then passed to the view for display.

The following are three key MVC components:

Model: It contains all of the data and the reasoning that goes with it.

Present data to the user or manage user interaction in this view.

A controller is a component that connects the Model and View components.

Let's look at each component in more detail:

View:

A View is the component of an application that represents how data is presented. The data gathered from the model data is used to build views. A view asks the model for data so that the user may see the resulting presentation.
The view also displays data from charts, diagrams, and tables. Any customer view, for example, will have all UI elements such as text fields, dropdowns, and so on.

Controller:

The Controller is the component of the program that controls user interaction. The controller interprets the user's mouse and keyboard inputs, which causes the model and view to alter accordingly.
To update the model's state, a Controller delivers commands (E.g., Saving a specific document). In addition, the controller sends orders to its associated view to modify the view's appearance (For example, scrolling a particular manuscript).