我有一个控制器:
@RequestMapping(value = "/take-item/{itemId}", method = RequestMethod.POST)
public String takeItem(final ModelMap model, @PathVariable final Long itemId) {
try {
scanService.takeItem(currentUser.getUserId(), itemId);
} catch (NoItemsInStockException e) {
// Not sure what to do here.
}
return "redirect:/";
}
以及此控制器重定向到的jsp文件:
<c:forEach var="item" items="${items}">
<form action="/take-item/${item.id}" method="POST">
<div class="item rounded m10">
<img src="${item.image}" width="150" height="150"/>
<h5>${item.productTitle}</h5>
<p>${item.price} <span class="nortal">LT</span></p>
<button class="btn btn-success">Imu!</button>
</div>
</form>
</c:forEach>
如果没有项目,如何在此jsp文件中显示错误?如果您还需要其他信息,请告诉我。
答案 0 :(得分:0)
尝试
<c:forEach var="item" items="${items}">
<form action="/take-item/${item.id}" method="POST">
<c:if test="item.quantity=='0'">
<h4 style="color:red"> Item out of stock</h4>
</c:if>
<div class="item rounded m10">
<img src="${item.image}" width="150" height="150"/>
<h5>${item.productTitle}</h5>
<p>${item.price} <span class="nortal">LT</span></p>
<button class="btn btn-success">Imu!</button>
</div>
</form>
</c:forEach>