2017-10-11 11 views
0

私は春に選択したコンボボックスの値を受け取る方法を見つけるのに苦労しています。春のコンボボックスから値を取得

これは、HTMLフォームです:ボタンがクリックされた後

<form method="post" multiple="true"> 
    Authhor: <label th:text="*{ownerName}" /><br /> 
    Title: <label th:text="*{name}" /><br /> 
    Description: <label th:text="*{description}" /><br /> 
    Price: €<label th:text="*{price}" /><br /> 
    Product: <select th:field="${productss}" th:remove="all-but-first"> 
     <option th:each="product : ${productss}" 
       th:value="${product.id}" th:text="${product.name + ' (+ €' + product.price + ')'}">Productname</option> 
    </select><br /> 
    <img width="250" heigth="250" th:src="*{plainURL}"/><br /> 
    <button align="right" class="btn" type="submit" name="add" ><span class="glyphicon glyphicon-check">Add to shopping cart</span></button><br /> 
</form> 

、このmethedは、コントローラで実行されます。

@RequestMapping(value = IMAGE_ID, method = RequestMethod.POST, params = {"add"}) 
public String add(@PathVariable("id") int id, HttpSession session, Model model) { 

... 

return "redirect:/cart"; 
} 

私はその中にコンボボックスから選択した値を受け取ることができますどのように方法?このような

+0

は、使用してみてくださいでした。<フォーム:選択パス= "製品"> –

答えて

0

変更あなたのselect要素:

<select th:field="${productss}" th:remove="all-but-first" name="product" > 
     <option th:each="product : ${productss}" 
       th:value="${product.id}" th:text="${product.name + ' (+ €' + product.price + ')'}">Productname</option> 
    </select><br /> 

そして、追加コントローラ@RequestParam

@RequestMapping(value = IMAGE_ID, method = RequestMethod.POST, params = {"add"}) 
public String add(@PathVariable("id") int id,@RequestParam Integer product, HttpSession session, Model model) { 

... 

return "redirect:/cart"; 
} 
+0

がこれを行うと、私はエラーになります:必須製品パラメータ 'product'が存在しません –

+0

変更を試みてください**製品の – mrtasln

+0

の整数*〜**文字列**これは私に同じエラーを与えます。 –

関連する問題