0
我想發佈一個字符串列表到我的控制器。 但它總是隻取第一個選定的值。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>
我的控制器:
@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";
}
用'@ RequestParam'代替'@ ModelAttribute'嘗試使用 –
感謝它! – silb78
Thomas Pawlitzki打了我幾分鐘,你應該驗證他的答案。 –