Я пытаюсь написать некоторый код для передачи списка элементов, скажем, идентификаторов, из формы тимили в контроллер Spring, чтобы я обновлял только те записи, которые выбраны. Я могу сделать выбор, но не размещать. Я пробовал большинство вещей онлайн, но безуспешно. Будем благодарны за любую помощь.
Код Thymeleaf
<form th:action="@{/invoicing/processInvoices/updateInvoice}" th:object="${invoiceDetails}" method="POST" >
<div >
<h4>Process Invoice</h4>
</div>
<fieldset>
<legend>Document Entries</legend>
<div class="row">
<div class="form-group col-sm-8">
<table border="1" th:id="invoiceTable" th:name="invoiceTable">
<thead>
<tr>
<th>No</th>
<th>ID No</th>
<!-- <th>Invoice No.</th>-->
<th>Student Name</th>
<th>Invoice Desc</th>
<th>Total</th>
<th>Status</th>
<th>Approvals/ <br/>
<input th:type="checkbox" th:id="checkAll" th:name="checkAll" onclick="selectAllCheckBox();"/>Sellect All
</th>
<!--<th> Action</th>-->
</tr>
</thead>
<tbody>
<tr class="col-sm-auto" th:each="invo : ${invoice}" th:size="100px">
<td th:text="${invoStat.count}"></td>
<td th:text="${invo.id}" th:hidden="hidden" th:name="id" th:id="id"></td>
<td th:text="${invo.docNumber}"></td>
<td th:text="${invo.studentNumber}"></td>
<td th:text="${invo.documentDescription}"></td>
<td th:text="${invo.amount}"></td>
<td th:text="${invo.status}"></td>
<td><input type="checkbox" th:name="approval" th:id="approval" /></td>
<!--<td><a th:href="@{'/invoicing/processInvoices/updateInvoice/{id}'(id=${invo.id})}">
<button class="btn btn-sm btn-success"><span class="fa fa-edit">
</span>Verify</button>
</a> </td>-->
</tr>
<tr>
<td colspan="4" ><b>Total</b></td>
<td colspan="2" th:text="${total}"></td>
<td colspan="2"></td>
</tr>
</tbody>
<tfoot>
</tfoot>
<button type="submit" class="btn btn-success" th:id="updateRecord" th:name="updateRecord">Verify</button>
<button type="submit" class="btn btn-warning">Clear</button>
</table>
</div>
</div>
</fieldset>
</form>
<script type="text/javascript">
$(function () {
//Assign Click event to Button.
$("#updateRecord").click(function () {
var message = "";
var x= [];
//Loop through all checked CheckBoxes in GridView.
$("#invoiceTable input[type=checkbox]:checked").each(function () {
var row = $(this).closest("tr")[0];
var id = $(this).closest("tr")[0];
message += row.cells[1].innerHTML;
/* message += " " + row.cells[2].innerHTML;
message += " " + row.cells[3].innerHTML;*/
message += "\n";
x.push(message);
});
$.ajax({
url:"/invoicing/processInvoices/updateInvoice",
type:"POST",
data:x,
contentType:"application/json; charset=utf-8",
dataType:"json",
//Display selected Row data in Alert Box.
//alert(message);
alert(x);
//alert(id);
});
});
</script>
</div>
Controller
@RequestMapping(path = "updateInvoice", method = RequestMethod.POST)
@ResponseBody
public String updateInvoice(@RequestParam List<Long> id, Model model){
System.out.println(id);
Образец распечатки ![enter image description here](https://i.stack.imgur.com/yXH9Z.png)