I have a list of records on GET
request which is shown on UI with a checkbox.
@GetMapping("/list")
public String list(Model model) {
model.addAttribute("records", createRecords());
return "list";
}
This is my Record
POJO
:
class Record {
private boolean selected;
private Integer id;
private String name;
private String phone;
//....
I am showing in UI as below:
<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>
I am having hard time to get the List
of selected records on POST
from UI
. I just gets one object back from POST
.
I want something like this in POST
mapping:
@PostMapping("/list")
public String select(@ModelAttribute ArrayList<Record> records) {
//... at least ids of selected records
//... or all the records back with selected
Please help.