@RestController
@RequestMapping("/user")
public class UserController {
@GetMapping("/login.do")
public ModelAndView login(){
System.out.println("显示登录界面");
return new ModelAndView("login");
}
@PostMapping("handle_login")
public ModelAndView handleLogin(String username,String password,
ModelMap model){
if ("robin".equals(username)){
if ("123".equals(password)){
model.put("message","欢迎回来");
return new ModelAndView("message");
}else {
model.put("message","密码错误");
return new ModelAndView("message");
}
}else {
model.put("message","用户名错误");
return new ModelAndView("message");
}
}
}
<!DOCTYPE html>
<html lang="en" xmlns:th="http://java.sun.com/jsf/composite">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>欢迎回来</h1>
<p th:text="${message}"></p>
</body>
</html>