2019-09-05 14:02:28.776 WARN 11096 --- [nio-8080-exec-3] osweb.servlet.PageNotFound:没有 GET /company/delete 的映射
我有一个使用 Spring Boot 和 JSP 页面的 CRUD 项目。
这是控制器删除方法
@PostMapping("delete/{coupid}")
public String removeCoupon(@PathVariable int coupid) {
couponService.deleteById(coupid);
return "couponRemoved";
}
有一种方法可以显示 JSP 页面中的所有优惠券:
@GetMapping("/read")
public String getAllCoupons(Model theModel) {
List<Coupon> theCoupon = companyService.getCurrentCompany().getCoupons();
theModel.addAttribute("theCoupon", theCoupon);
return "showAllCoupons";
}
只需将每个优惠券添加到模型中,然后重定向到显示所有优惠券的页面并循环:
<table class="i">
<tr>
<th>id</th>
<th>title</th>
<th>start</th>
<th>end</th>
<th>amount</th>
<th>type</th>
<th>message</th>
<th>price</th>
<th>image</th>
</tr>
<c:forEach var="tempCoupon" items="${theCoupon}" >
<tr>
<td> ${tempCoupon.coupid} </td>
<td> ${tempCoupon.title} </td>
<td> ${tempCoupon.startd} </td>
<td> ${tempCoupon.endd} </td>
<td> ${tempCoupon.amount} </td>
<td> ${tempCoupon.type} </td>
<td> ${tempCoupon.message} </td>
<td> ${tempCoupon.price} </td>
<td> ${tempCoupon.image} </td>
<td><a href="${pageContext.request.contextPath}/company/delete?coupid=${tempCoupon.coupid}"> Remove ${tempCoupon.coupid} </a></td>
</tr>
</c:forEach>
</table>
正如您在 JSP c:forEach 循环中看到的那样,我还包含了一个 href 链接:
<td><a href="${pageContext.request.contextPath}/company/delete?coupid=${tempCoupon.coupid}"> Remove ${tempCoupon.coupid} </a></td>
它在循环中获取当前优惠券并将其 id 放入链接中。
当我运行它并单击删除时,我得到了这个:
2019-09-05 14:02:28.776 WARN 11096 --- [nio-8080-exec-3] osweb.servlet.PageNotFound:没有 GET /company/delete 的映射