Search⌘ K
AI Features

Model - Part 2

Explore adding search functionality to your Spring MVC application. Learn to create a Player service, use dependency injection, handle GET requests, and update views to display player details based on user input.

In this lesson, we will add search functionality to our Spring MVC application. Now that we have a form for taking the player name as input (search-player-form.jsp), we will add functionality to return information about the player chosen by the user.

Player class

We will create a Player class in io.datajek.springmvc.tennisplayerweb package with name, nationality, date of birth, and number of titles as members. We will create getters and a constructor for initializing a Player object.

@Component
public class Player {
private int id;
private String name;
private String nationality;
private Date birthDate;
private int titles;
//constructor
//getter methods
}
Player class

PlayerService class

Next, we will create a PlayerService class in io.datajek.springmvc.tennisplayerweb package. The @Service annotation tells Spring that this class is intended for ...