【发布时间】:2016-02-03 01:40:38
【问题描述】:
我正在尝试创建一个表格来显示已添加的所有日志的列表。除了显示信息之外,我还希望有另一列复选框,单击这些复选框后,我可以使用相应的删除按钮将其删除。
我遇到的问题是我无法将复选框中的值放入 Longs 数组中。我还想保持我的表格正确显示的功能。
对于我的表,我有以下代码:
<form method="post" th:action="@{/projects/log/delete/}" th:object="${deleteForm}">
<div th:each="log : ${allLogs}" class="row">
<tbody>
<tr class="active">
<td>
<input type="checkbox" th:field="*{logIds}" th:value="${log.id}" />
</td>
<td th:text="${log.teamUsed}"></td>
<td th:text="${log.opponentStarters}"></td>
<td th:text="${log.opponentOthers}"></td>
<td th:text="${log.myStarters}"></td>
<td th:text="${log.myOthers}"></td>
<td th:text="${log.result}"></td>
</tr>
</tbody>
</div>
<button type="submit" id="deleteButton" class="hidden"></button>
</form>
我试图将复选框值放入的表单是:(log.id 很长)
public class LogDeleteForm {
private List<Long> logIds = new ArrayList<>();
public List<Long> getLogIds() {
return logIds;
}
public void setLogIds(List<Long> logIds) {
this.logIds = logIds;
}
}
在我的控制器中,我的视图有以下设置:
@RequestMapping(value = "pokemon_log", method = RequestMethod.GET)
public String view(Model model) {
model.addAttribute("addForm", new logForm());
model.addAttribute("deleteForm", new logDeleteForm());
model.addAttribute("allLogs", logService.getAllLogs());
return "log";
}
我能够执行删除,但我无法获取我想要删除的 ID。如何将复选框值放入 long 列表中?
【问题讨论】:
标签: java html spring spring-mvc thymeleaf