我正在按照给定的链接提交要保存在数据库中的表数据
http://viralpatel.net/blogs/spring-mvc-multi-row-submit-java-list/
但是给定链接和我的实现之间的区别在于,链接的前端使用 JSTL(JSP),而我使用的是 Thymeleaf(HTML)
以下是正在使用的文件
HTML 表单:
<form method="POST" th:action="@{/updateAllRules}" th:field="${ruleForm}">
<table>
<thead>
<tr>
<th>S No</th>
<th>Title</th>
<th>Body</th>
</tr>
</thead>
<tbody>
<tr th:each="ruleModel,iteration : ${allRules}">
<td th:text="${ruleModel.id}"></td>
<td><input type="text" th:name="${'rule'+iteration.index+'.title'}" th:value="${ruleModel.title}"></td>
<td><input type="text" th:name="${'rule'+iteration.index+'.body'}" th:value="${ruleModel.body}"></td>
</tr>
</tbody>
</table>
<br>
<input type="submit" value="Update All">
</form>
Run Code Online (Sandbox Code Playgroud)
模型类:
public class Rule {
private Integer id;
private Date timestamp;
private String title;
private String body;
// constructor and Getter/Setters
}
Run Code Online (Sandbox Code Playgroud)
表格类:
public class RuleForm {
private List<Rule> rule;
public List<Rule> getRule() {
return …Run Code Online (Sandbox Code Playgroud)