Model - Part 2
Learn to pass data between controllers by implementing search functionality.
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.
@Componentpublic 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 ...