尝试将所选项目的值从下拉列表发布到我的控制器时遇到麻烦。
我正在使用此方法填充下拉列表:
@RequestMapping(value = {"/picking"}, method = RequestMethod.GET)
public String page(Model model) {
List<PropertiesEnvironment> codeList = (List<PropertiesEnvironment>) environmentRepository.findAll();
model.addAttribute("code",codeList);
return "picking";
}
我的JSP下拉列表:
<form:form modelAttribute="search" action="drop" class="dropdown-environments" method="POST">
<form:select path="code" id="env-selection" onchange="this.form.submit()" class="form-control select-filter select2-hidden-accessible" aria-hidden="true">
<c:forEach items="${code}" var="c">
<form:option value="${c.code}">${c.code}</form:option>
</c:forEach>
</form:select>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
</form:form>
这是我的POST控制器:
@RequestMapping(value = "/picking", method = RequestMethod.POST)
public String page2( @ModelAttribute("search") PropertiesEnvironment search,BindingResult res) {
System.out.println(search.getCode());
return "picking";
}
当我选择一个项目时,没有对象传递给我的控制器。
感谢您的帮助!