一句话,使用名字前缀,分别绑定。
@Controller @RequestMapping("/demo/formbean") public class FormBeanController { @Autowired private FormBeanService formBeanService;
@InitBinder("formBean1") public void initBinderFormBean1(WebDataBinder binder) { binder.setFieldDefaultPrefix("formBean1."); } @InitBinder("formBean2") public void initBinderFormBean2(WebDataBinder binder) { binder.setFieldDefaultPrefix("formBean2."); } @RequestMapping("/save12") @ResponseBody public ModelAndView save12(FormBean1 formBean1, FormBean2 formBean2){ formBean2 = formBeanService.saveFromBean12(formBean1, formBean2); ModelAndView mav = new ModelAndView(); mav.setViewName("redirect:/demo/formbean/edit12/"+formBean2.getId()); return mav; } }
<form class="form-horizontal" id="formBean1Form" method="post"> <div class="control-group"> <label class="control-label" for="code">FB1编号</label> <div class="controls"> <input type="hidden" id="formBean1.id" name="formBean1.id" value="${formBean2.formBean1.id }" /> <input type="text" id="formBean1.code" name="formBean1.code" value="${formBean2.formBean1.code }" /> </div> </div> <div class="control-group"> <label class="control-label" for="name">FB1名称</label> <div class="controls"> <input type="text" id="formBean1.name" name="formBean1.name" value="${formBean2.formBean1.name }" > </div> </div> <div class="control-group"> <label class="control-label" for="name">FB2编号</label> <div class="controls"> <input type="hidden" id="formBean2.id" name="formBean2.id" value="${formBean2.id }" /> <input type="text" id="formBean2.code" name="formBean2.code" value="${formBean2.code }" > </div> </div> <div class="control-group"> <label class="control-label" for="name">FB2名称</label> <div class="controls"> <input type="text" id="formBean2.name" name="formBean2.name" value="${formBean2.name }" > </div> </div> <div class="control-group"> <div class="controls"> <button type="submit" class="btn" onclick="this.form.action='${ctx}/demo/formbean/save12'">提交</button> </div> </div> </form>
|