- Building Web Apps with Spring 5 and Angular
- Ajitesh Shukla
- 176字
- 2021-07-02 19:38:20
The RequestParam annotation
In this section, we will learn how to use the RequestParam annotation for reading web request parameters in the controller class. The following image shows what the signup form looks like with three input fields such as Nick Name, Email address, and Password:

On submission of the preceding form, the user request parameters will be handled using the @RequestParam annotation. The RequestParam annotation is used to bind a method parameter to a web request parameter. The following code displays the binding of method parameters such as nickname, emailAddress, and password with web request parameters such as nickname, emailaddress, and password respectively. In simple words, the frontend has to send parameters with keys as nickname, email address, and password for the code given next to work.
@Controller
@RequestMapping("/account/*")
public class UserAccountController {
@GetMapping("/signup")
public String signup() {
return "signup";
}
@PostMapping("/signup/process")
public String processSignup(ModelMap model,
@RequestParam("nickname") String nickname,
@RequestParam("emailaddress") String emailAddress,
@RequestParam("password") String password) {
model.addAttribute("login", true);
model.addAttribute("nickname", nickname);
return "index";
}
}