2017-10-27 3 views
0

こんにちは、あなたが私を助けることができることを願っています。スプリングリターンオブジェクトのボタンをクリックしてください

@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を書く必要がありますボタン。

答えて

0

あなたが入力隠された以下のようにフォームのタブの中に隠さ入力が必要になります。

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

+0

と私は唯一のそれらの2 2のショーを必要とするので、私は、入力をしたくない場合はどのような情報のために? ? – muhmuhhum

+0

入力を追加しないと、Controllerで値を取得できません。完全なレストランには、IDまたはキーを隠した入力として追加することをお勧めします。その後、サーバー側でIDをもう一度取得します。 – user2485755

関連する問題