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

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";
}
}
主站蜘蛛池模板: 古蔺县| 浦北县| 额尔古纳市| 富阳市| 阿图什市| 海晏县| 同仁县| 中超| 福清市| 大城县| 潼关县| 宁城县| 荣成市| 儋州市| 来宾市| 衡阳县| 鄱阳县| 华安县| 滁州市| 兰溪市| 如东县| 苏尼特右旗| 西林县| 武穴市| 沐川县| 华坪县| 庄浪县| 应用必备| 宁蒗| 屏东市| 广南县| 顺昌县| 额尔古纳市| 曲周县| 阿坝县| 于都县| 延长县| 兴山县| 镇江市| 韶关市| 甘孜县|