Search⌘ K

Team and User Controllers

Explore creating TeamController and UserController to handle basketball teams and users in a scalable Spring Boot application. Learn to build views for user and team lists, update menus with active highlighting, and implement root URL redirection for smooth navigation.

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:

Java
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:

Java
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
  • templates/teams/list.html
...