Spring boot 如何从不是pojo一部分的html传递字段?
在我的spring boot应用程序中: POJO: 此处为html模板:Spring boot 如何从不是pojo一部分的html传递字段?,spring-boot,Spring Boot,在我的spring boot应用程序中: POJO: 此处为html模板: <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <title th:text="${appName}">Template title</title> <link th:href="@{/public/style.css}" rel="stylesheet"/
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="${appName}">Template title</title>
<link th:href="@{/public/style.css}" rel="stylesheet"/>
</head>
<body>
<div id="container">
<h2 align="center">Registration new user</h2>
<form th:action="@{/registration.html}" method="post">
<label for="username">Username</label>
<input type="text" id="username" name="username" autofocus="autofocus"/>
<label for="password">Password</label>
<input type="password" id="password" name="password"/>
<label for="retypePassword">Retype password</label>
<input type="password" id="retypePassword" name="retypePassword"/>
<input id="submit" type="submit" value="Registration"/>
</form>
<p th:if="${registrationError}" th:text="${registrationError}" class="error"></p>
</div>
</body>
</html>
模板标题
注册新用户
用户名
密码
验证登陆密码
如您所见,我从html中传递POJOUser
,并检查isusername
和password
是否已填充。
美好的
但是我还需要检查password
和retypePassword
是否相等。
问题是,retypePassword
不是POJOUser
的一部分(没有属性retypePassword
)。
如何将
retypePassword
从html传递到方法registartionNewUser
以检查password
和retypePassword
?将retypePassword
作为方法registartionNewUser
中的另一个参数
public String registartionNewUser(User user, String retypePassword, Model model)
此帮助信息:公共字符串注册表项OnnewUser(用户-用户,模型模型,@RequestParam(name=“retypePassword”,required=true)字符串retypePassword)
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="${appName}">Template title</title>
<link th:href="@{/public/style.css}" rel="stylesheet"/>
</head>
<body>
<div id="container">
<h2 align="center">Registration new user</h2>
<form th:action="@{/registration.html}" method="post">
<label for="username">Username</label>
<input type="text" id="username" name="username" autofocus="autofocus"/>
<label for="password">Password</label>
<input type="password" id="password" name="password"/>
<label for="retypePassword">Retype password</label>
<input type="password" id="retypePassword" name="retypePassword"/>
<input id="submit" type="submit" value="Registration"/>
</form>
<p th:if="${registrationError}" th:text="${registrationError}" class="error"></p>
</div>
</body>
</html>
public String registartionNewUser(User user, String retypePassword, Model model)