【发布时间】:2020-08-25 02:34:05
【问题描述】:
以下函数在CustomerController.java
中定义 @GetMapping("/showFormForUpdate")
public String showFormForUpdate(@RequestParam("customerId") int theId, Model theModel) {
// get the customer from our service
Customer theCustomer = customerService.getCustomer(theId);
// set customer as a model attribute to pre-populate the form
theModel.addAttribute("customer", theCustomer);
// send over to out form
return "customer-form";
}
@GetMapping("/delete")
public String deleteCustomer(@RequestParam("customerId") int theId) {
// delete the customer
customerService.deleteCustomer(theId);
return "redirect:/customer/list";
}
list-customer.jsp 文件如下。
<!-- loop over and print out customers -->
<c:forEach var="tempCustomer" items="${customers}">
<!-- construct an "update" link with customer id -->
<c:url var="updateLink" value="/customer/showFormForUpdate">
<c:param name="customerId" value="${tempCustomer.id}" />
</c:url>
<!-- construct an "delete" link with customer id -->
<c:url var="deleteLink" value="/customer/delete">
<c:param name="customerId" value="${tempCustomer.id}" />
</c:url>
<tr>
<td> ${tempCustomer.firstName} </td>
<td> ${tempCustomer.lastName} </td>
<td> ${tempCustomer.email} </td>
<td>
<!-- display the update link -->
<a href="${updateLink}">Update</a>
|
<a href="${deleteLink}"
onclick="if (!(confirm('Are you sure you want to delete this customer?'))) return false">Delete</a>
</td>
</tr>
</c:forEach>
当我点击Update链接时,CustomerController.java中的showFormForUpdate函数被调用。
但是,当我单击 Delete 链接时,deleteCustomer 函数不会被调用,也不会显示任何 WARNING: No mapping for GET error。我在删除 onclick="if (!(confirm('Are you sure you want to delete this customer?'))) return false" 后尝试了这个功能。但问题依然存在。
有人可以帮我解决这个问题吗?
【问题讨论】:
-
您的删除
a href链接正在被您的onclick函数覆盖。 -
但是当我删除onclick功能时它仍然不起作用。
-
@shinjw 如果我将“deleteLink”替换为“updateLink”,页面将被重定向到其他页面。所以我认为 deleteLink 有一些问题。但我不知道它是什么。
标签: javascript html spring-mvc jsp