【发布时间】:2018-02-25 07:33:13
【问题描述】:
我有一个关于GET 请求的记录列表,它显示在 UI 上并带有一个复选框。
@GetMapping("/list")
public String list(Model model) {
model.addAttribute("records", createRecords());
return "list";
}
这是我的RecordPOJO:
class Record {
private boolean selected;
private Integer id;
private String name;
private String phone;
//....
我在 UI 中显示如下:
<th:block th:each = "record : ${records}">
<tr>
<td><input type="checkbox" th:field="*{selected}" th:checked="${record.selected}" /></td>
<td th:field="*{id}" th:text="${record.id}" />
<td th:field="${name}" th:text="${record.name}" />
<td th:field="${phone}" th:text="${record.phone}" />
</tr>
</th:block>
我很难从UI 获取POST 上选定记录的List。我只从POST 拿回了一个对象。
我想要在POST 映射中这样的东西:
@PostMapping("/list")
public String select(@ModelAttribute ArrayList<Record> records) {
//... at least ids of selected records
//... or all the records back with selected
请帮忙。
【问题讨论】:
-
@ben3000 我有使用相同对象的限制,而不是使用具有主要对象列表的包装对象。
标签: java spring-mvc spring-boot thymeleaf