当我尝试从我的数据库中删除一个条目时,我遇到了这个问题,并且在我的html页面中删除了一个错误页面,而不是我想要被重命名的位置。我试图删除的条目是“order”。这位是我的财务总监:
@RequestMapping(value = "supplier/orders/review")
public String reviewOrders(Model model){
model.addAttribute("orders", ordersRepository.findAll());
return "ReviewOrders";
}
@RequestMapping(value = "/deleteOrder/{id}", method = RequestMethod.GET)
public String deleteOrder(@PathVariable("id") Integer id){
Orders orders = ordersRepository.getById(id);
ordersRepository.delete(orders);
return "redirect:/SupplierDashboard";
}这是我的html
</tr>
<tr th:each="orders:${orders}" class="table-row">
<td th:text="${orders.id}">Id</td>
<td th:text="${orders.product_name}">Name</td>
<td th:text="${orders.product.price}">Price</td>
<td th:text="${orders.product.description}">desc</td>
<td th:text="${orders.product.category}">category</td>
<td th:text="${orders.product.quantity}">quantity</td>
<td th:text="${orders.product.supplier.firstName}">supplier name</td>
<td>
<a th:href="@{/deleteOrder/{id} (id = ${orders.id})}" class="btn btn-danger ml-2">Delete</a>
</td>我被重定向到的url是http://localhost:8080/deleteOrder/1,我得到了这个错误:
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Jun 21 22:49:08 EEST 2022
There was an unexpected error (type=Not Found, status=404).
No message available我试过在其他问题上看到的几乎所有东西。有人能帮我吗?
发布于 2022-06-22 04:26:52
一步一步把它拆开。
在得到错误之前,执行print语句以查看id是否被打印。检查您是否得到了正确的订单,打印语句的作用很大。
另外,当您重定向时,它需要一个get方法。我这么说是因为我假设您在控制器中创建了一个SupplierDashboard和html/thymeleaf模板的映射,所以检查它是post还是get。
您的id可能没有打印在您的java代码中,这可能会导致问题。
https://stackoverflow.com/questions/72706397
复制相似问题