2017-10-11 2 views
0

저는 봄에 선택한 콤보 박스 값을받는 방법을 찾기 위해 고심하고 있습니다. 이 methed 컨트롤러에서 실행되고, 버튼이 클릭되면봄에 콤보 박스에서 값을 얻으십시오.

<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> 

:

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

... 

return "redirect:/cart"; 
} 

가 어떻게 점에서 콤보 박스에서 선택된 값을 수신 할 수

은 HTML 형태 방법? 이 같은

+0

이 사용하려고 했 <형태 : 선택 경로 = "제품"> –

답변

0

변경 당신의 선택 요소 :

<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

변경하십시오 ** 정수 ** to ** String ** 제품 – mrtasln

+0

여전히 동일한 오류가 발생합니다. –

관련 문제