In this recipe, we will define in one place a route prefix shared by all the routes of a controller. We will start the routes of the UserController
controller with /user
.
Here are the steps to set a route prefix:
Add
@RequestMapping
with the common route prefix to the controller class:@Controller @RequestMapping("/user") public class UserController { ... }
Add
@RequestMapping
with the remainder of the route to the controller methods:@RequestMapping("/list") public void userList() { ... } @RequestMapping("/add") public void addUser() { ... }