Associating a route to a controller method
In this recipe, you will learn how to define a controller method to be executed for a given route.
How to do it…
Here are the steps for creating a controller method for a given route:
Create a controller class in your controller package (for example,
com.springcookbook.controller
). This is a normal Java class annotated with@Controller
:@Controller public class UserController { ... }
Add a controller method. This is a standard Java method annotated with
@RequestMapping
, which takes the route as a parameter:@RequestMapping("/user/list") public void userList() { ... }
How it works…
A request with the /user/list
route will execute the userList()
method.