2017-02-20 7 views
0

私は自分のコントローラに文字列のリストを投稿したいと思います。 しかし、常に最初に選択された値を取るだけです。Spring Boot with Thymeleaf投稿一覧

私thymeleaf HTMLフォーム:

<form action="/add" method="post"> 
    <div class="form-group"> 
     <label for="roleId">ID</label> <input type="text" class="form-control" id="roleId" name="id" required="required" /> 
    </div> 
    <div class="form-group"> 
     <label for="rolePrivileges">Privileges</label> 
     <select class="form-control" id="rolePrivileges" name="privileges" multiple="multiple" size="10" required="required"> 
      <option th:each="type : ${privilegesList}" th:value="${type}" th:text="${type}">Privilege</option> 
     </select> 
    </div> 
    <button type="submit" class="btn btn-default">Create</button> 
</form> 

私のコントローラ:私はあなたがそれはModelAttributeはありませんが、あなたが受け取る

@RequestParam("privileges") 

でprivilgesに注釈を付けるために持っていると思う

@RequestMapping(value = "/add", method = RequestMethod.POST) 
public String addSomething(Model model, @ModelAttribute("id") String id, 
     @ModelAttribute("privileges") List<String> privileges) { 
    // add something with a service 
    return "redirect:/roles"; 
} 
+1

'@ ModelAttribute'の代わりに' @ RequestParam'を試してください –

+0

ありがとうございます! – silb78

+0

トーマス・パウリツキーが数分で私を倒しました。あなたは彼の答えを検証するべきです。 –

答えて

関連する問題