弹簧返回对象上的按钮单击出列表



嗨,伙计们希望你能帮助我,因为我现在无法走得更远

我有我的控制器。

@RequestMapping(value="/kundenseite", method= RequestMethod.GET)
    public String kundenLogin(ModelMap model) {
        if(kundeComponent.getKunde() != null) {
        List<Restaurant> restaurants = restaurantService.alleRestaurants();
        model.addAttribute("restaurants", restaurants);
        return "kundenseite";
        }else {
            return "redirect:/kunde/login";
        }
    }
    @RequestMapping(value="/kundenseite", method= RequestMethod.POST)
    public String kundenLoginAnswer(ModelMap model, @ModelAttribute Restaurant restaurant) {
        System.out.println(restaurant.toString());
        return "kundenseite";

还有我的 jsp 文件

<%@ include file="common/header.jspf" %>
<div class="jumbotron text-center">
  <h1>MiMiMi Lieferservice</h1>
  <p>Der schnellste Lieferservice von Passpick</p> 
</div>
<div style="margin-right:auto; margin-left:auto; width: 33%">
<h2 style="text-align: center">Restaurant wählen</h2>
<div class="well">
<c:forEach items="${restaurants}" var="restaurant">
<form:form modelAttribute="${restaurant}" method="post">
<div style="margin-top: 8px" class=col-sm-4 >${restaurant.name}</div>
<div style="margin-top: 8px" class=col-sm-4 >${restaurant.restaurantTyp}</div>
<button type="submit">Bestellen</button>
</form:form>
<br style="clear:both;" />
</c:forEach>
</div>
</div>
</body>
</html>

如果用户按下按钮,我想返回餐厅。但我不知道如何做到这一点,我的想法是使用表格,但我无法让它将完整的餐厅对象发回

如果没有解决方案,我必须用按钮写id。

您需要隐藏在表单选项卡中的输入,如下输入隐藏:

<input type="hidden" name="name" value="${restaurant.name}">
<input type="hidden" name="restaurantTyp" value="${restaurant.restaurantTyp}">

最新更新