官术网_书友最值得收藏!

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

Figure: New User Signup form

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";
}
}
主站蜘蛛池模板: 万全县| 桐梓县| 广宗县| 咸丰县| 无极县| 安吉县| 松原市| 巴青县| 通山县| 南投市| 阿瓦提县| 图木舒克市| 天峻县| 阜阳市| 柳河县| 潞城市| 许昌市| 延吉市| 桦川县| 嘉善县| 福贡县| 尼玛县| 旬阳县| 洛川县| 益阳市| 海淀区| 永康市| 通州市| 彰武县| 普宁市| 芷江| 锦州市| 舒城县| 蚌埠市| 牙克石市| 铜陵市| 黎川县| 渝中区| 邯郸市| 东丽区| 二手房|