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

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";
}
}
主站蜘蛛池模板: 蒙自县| 桐庐县| 丰县| 旬阳县| 凤庆县| 阜宁县| 鹰潭市| 涡阳县| 辉县市| 盖州市| 靖江市| 岳西县| 禹州市| 海盐县| 凌海市| 西贡区| 香河县| 温泉县| 玉林市| 五河县| 宁武县| 凯里市| 霍邱县| 扶绥县| 凤山县| 南丰县| 湾仔区| 宁德市| 桐梓县| 萍乡市| 都江堰市| 聊城市| 堆龙德庆县| 潍坊市| 西林县| 湄潭县| 咸阳市| 图们市| 高青县| 若尔盖县| 镇康县|