用户登陆HTML login页面。命名为login.html。
下面页面必须保存在 Spring Boot程序的 resources/templates 文件夹中。
<!DOCTYPE html>
<html lang="en" xmlns:th="#34;> ❶
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
<form action="/" method="post"> ❷
Username: <input type="text" name="username" /><br /> ❸
Password: <input type="password" name="password" /><br /> ❸
<button type="submit">Log in</button> ❹
</form>
<p th:text="${message}"></p> ❺
</body>
</html>
①用到的模版引擎 templating engine
②定义HTML form发送客户信息凭证(credentials)给服务器。
③定义输入框发送用户名,密码。
④用户点击登陆Log in按钮,发送携带用户信息凭证的HTTP POST请求。
⑤显示 HTTP POST请求结果的信息。
接下来定义controller,用来接受之前的page的request/请求。
controller action 映射到web app’s root path (“/”)。
命名为 LoginController
下列代码为controller action示例代码
@Controller ❶
public class LoginController {
@GetMapping("/") ❷
public String loginGet() {
return "login.html"; ❸
}
@PostMapping("/") ④
public String loginPost(
@RequestParam String username, ⑤
@RequestParam String password, ⑤
Model model ⑥
) {
boolean loggedIn = false; ⑦
if (loggedIn) { ⑧
model.addAttribute("message", "You are now logged in."); ⑧
} else { ⑧
model.addAttribute("message", "Login failed!"); ⑧
}
return "login.html"; ⑨
}
}
①通过@Controller stereotype annotation注释,定义Spring MVC controller文件。
②把controller action映射到application root 根目录下。
③返回渲染过的登陆页面。
④controller action映射到login 页面的HTTP POST 请求
⑤通过HTTP request 参数获取客户信息凭证(credentials)
⑥声明Model,来发送message value给视图view
⑦用来存储登录结果
⑧根据登录的结果,返回特定的信息返回给视图页面。
⑨返回登录页面
The majority of new cases worldwide are in neonates in third world countries
5 Mhz transducer for the common carotid artery
Due to a smaller number of cases, the risk estimates were less precise than the risk estimates for overall ovarian cancer
If welded, the gas tank holder must be at least 5 away from the vertical sheet metal at the rear seat speaker deck area
The researchers found that women who used Clomid without medical supervision tripled their risk of having a baby born with a birth defect If you make it through On ramp or just show up and continue coming, you are a Cfer and you can get through any workout
For mucus layer visualization, intestines were fixed in Carnoy s fixative for 7 d