谁能解释一下 thymeleaf 的提交按钮在以下代码中是如何工作的?
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
layout:decorator="master">
<head>
<title>LoginPage</title>
</head>
<body>
<h1>Login Page</h1>
<!-- Any content you put in the div fragment below will appear on the page-->
<div class="container">
<div class="row">
<div class="span8">
<P th:if="${loginError}" >Wrong User or Password</P>
<form th:action="@{/new}" th:Object="${messageForm}"
method="post">
<label for ="User">User Name</label>
<input type="text" th:field="*{user}"/><br/>
<label for ="password">Password</label>
<input type="password" th:field="*{password}"/><br/>
<input type="submit" value="Login" />
</form>
</div>
</div>
</div>
</body>
</html>
最佳答案
<form>
模板被渲染为带有 POST
的标准表单。您提交时调用的电话。
该框架添加的内容是,表单字段动态绑定(bind)到底层对象,由 th:Object="${messageForm}"
引用。属性。
每个字段都是通过调用 messageForm
上的方法来计算的带有 th:field="*{password}"
的对象语法。
最后,POST
调用通过评估 th:action="@{/new}"
创建的 URL属性,可能相对于当前页面。
关于java - thymeleaf 提交按钮代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15539287/