我用自定义解决方案来解决这个问题,我实现它通过发送一个 阵列 的 证书 ID到控制器和接收它作为 requestParam
。需求更改定义如下。
<tr> <td>Certificate</td> <td> <th:block th:each="certificate : ${certificates}"> <input type="checkbox" name="cers" th:value="${certificate.id}"/> <label th:text="${certificate.name}"></label> </th:block> </td></tr>
@RequestMapping(value = "/add" , method = RequestMethod.POST)public String addSave( @ModelAttribute("employee")Employee employee , @RequestParam(value = "cers" , required = false) int[] cers , BindingResult bindingResult , Model model) {if(cers != null) { Certificate certificate = null ; for (int i = 0; i < cers.length; i++) { if(certificateService.isFound(cers[i])) { certificate = new Certificate(); certificate.setId(cers[i]); employee.getCertificates().add(certificate); } } for (int i = 0; i < employee.getCertificates().size(); i++) { System.out.println(employee.getCertificates().get(i)); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)