私はコントローラーを持っています:
@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ファイルにエラーを表示するにはどうすればよいですか?他に何か必要な場合はお知らせください。
試してみてください
<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>
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加