Team and User Controllers

Learn how to implement and utilize team and user controllers.

We'll cover the following...

We will start by creating a couple of controllers:

  • com.tamingthymeleaf.application.user.web.UserController: This controller is responsible for the users of the application. In our example, these are the basketball players, the coaches, the administrators, etc.
  • com.tamingthymeleaf.application.team.web.TeamController: This controller is responsible for the teams within the application.

This is the code for the UserController:

Press + to interact
package com.tamingthymeleaf.application.user.web;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/users")
public class UserController {
@GetMapping
public String index(Model model) {
return "users/list";
}
}

The TeamController is very similar:

Press + to interact
package com.tamingthymeleaf.application.team.web;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/teams")
public class TeamController {
@GetMapping
public String index(Model model) {
return "teams/list";
}
}

We also need respective views:

  • templates/users/list.html
...