@RequestMapping("/login")
public String login(User user, Model model) {
if ("bianchengbang".equals(user.getName())
&& "123456".equals(user.getPwd())) {
model.addAttribute("message", "登录成功");
return "main";
} else {
model.addAttribute("message", "用户名或密码错误");
return "login";
}
@RequestMapping("/login")
public String login(String name, String pwd, Model model) {
if ("bianchengbang".equals(user.getName())
&& "123456".equals(user.getPwd())) {
model.addAttribute("message", "登录成功");
return "main";
} else {
model.addAttribute("message", "用户名或密码错误");
return "login";
}
}
- 通过 HttpServletRequest 接收请求参数⭐
@RequestMapping("/login")
public String login(HttpServletRequest request, Model model) {
String name = request.getParameter("name");
String pwd = request.getParameter("pwd");
if ("bianchengbang".equals(name)
&& "123456".equals(pwd)) {
model.addAttribute("message", "登录成功");
return "main";
} else {
model.addAttribute("message", "用户名或密码错误");
return "login";
}
}
- 通过 @PathVariable 接收 URL 中的请求参数
@RequestMapping("/login/{name}/{pwd}")
public String login(@PathVariable String name, @PathVariable String pwd, Model model) {
if ("bianchengbang".equals(name)
&& "123456".equals(pwd)) {
model.addAttribute("message", "登录成功");
return "main";
} else {
model.addAttribute("message", "用户名或密码错误");
return "login";
}
}
@RequestMapping("/login")
public String login(@RequestParam String name, @RequestParam String pwd, Model model) {
if ("bianchengbang".equals(name)
&& "123456".equals(pwd)) {
model.addAttribute("message", "登录成功");
return "main";
} else {
model.addAttribute("message", "用户名或密码错误");
return "login";
}
}
- 通过 @ModelAttribute 接收请求参数⭐
@RequstMapping("/login")
public String login(@ModelAtrribute("user") User user,Model model){
id("bb".equals(name)&& "1234".equals(pwd)){
model.addAttribute("message"," 登陆成功");
return"main";
} else{
model.addAtrribute("message","错误");
return "login";
}
}