Model
Explore how the Model acts as a data container in Spring MVC to carry information between controllers and views. Learn to pass form data to the controller, add attributes to the Model, and access this data in view templates using expression language syntax. This lesson will help you understand the separation of concerns crucial for building scalable Spring MVC applications.
We'll cover the following...
In a Spring MVC application, the Model manages data. It serves as a container for carrying data between different components of the application. When the Controller retrieves data from sources like databases, web services, or Spring beans, it places this data into the Model. The View template can access this data to display it to the client. The Model acts as the intermediary for transporting data between the various parts of the application.
In this lesson, we will first pass the Model to our Controller class, then add some data to it and finally show how the data in the Model is accessed in the View page.
We have created a form in search-player-form.jsp that takes a player name as input. The code for the form is reproduced below:
When "Submit" is clicked, a GET request invokes the processForm() method of the TennisPlayerController because ...