我有一个有一些订单的客户列表,我将它们全部显示在一个表格中。我添加了一个按钮,以便在需要时删除每个订单。
这是我如何显示它们的表格。
<table id="customers">
<tr>
<th>Customer</th>
<th>Order</th>
<th>Action</th>
</tr>
<div th:each="customer : ${customers}">
<tr>
<td th:text="${customer.name}" style="font-weight: bold;"></td>
<td></td>
<td></td>
</tr>
<tr th:each="order : ${customer.orders}" >
<td></td>
<td th:text="${order.name}">
<td>
<a th:href="@{/manager/customer/{cid}(cid=${customer.id})/order/{oid}(oid=${order.id})}" class="button">Remove order</a>
</td>
</tr>
</div>
</table>
在我的 Controller 类中,我有处理删除的方法。
@GetMapping("/manager/customer/{cid}/order/{oid}")
public String deleteCustomerOrder(@PathVariable(value="cid") Long cid, @PathVariable(value="oid") Long oid, Model model) {
Customer c = customerService.findCustomerById(cid);
//do stuff
return "/manager/customerOrders";
}
当我尝试删除特定订单时,出现以下错误
无法将“java.lang.String”类型的值转换为所需的“java.lang.Long”类型;嵌套异常是 java.lang.NumberFormatException:对于输入字符串:“{cid}(cid=${customer.id})”
路径如下所示: http://localhost:8080/manager/customer/%7Bcid%7D(cid= $%7Bcustomer.id%7D)/order/2
我在获取 ID 的方式上做错了吗?