- 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";
}
}
- RTC程序設計:實時音視頻權威指南
- Cassandra Design Patterns(Second Edition)
- 秒懂設計模式
- Jupyter數據科學實戰
- JavaScript入門經典
- 批調度與網絡問題的組合算法
- INSTANT Sinatra Starter
- Mastering Unity 2D Game Development(Second Edition)
- Android項目實戰:手機安全衛士開發案例解析
- Android開發三劍客:UML、模式與測試
- Hands-On GUI Programming with C++ and Qt5
- Orleans:構建高性能分布式Actor服務
- 實戰Java高并發程序設計(第2版)
- C++程序設計教程(第2版)
- Java EE 7 with GlassFish 4 Application Server