spring mvc 绑定两个对象进行表单提交
//form表单是可以提交多个对象的
/** * 保存简历 * @param bean 简历信息 * @param jobIntention 求职意向 * @return */ @Logined @RequestMapping(value = "/job_resume_add", method = RequestMethod.POST) public ModelAndView doAdd(JobResume bean,JobIntention jobIntention) { Timestamp now =DateHelper.now(); bean.setRecordTime(now); jobResumeService.insert(bean); jobIntention.setRecordTime(now); jobIntention.setJobResumeId(bean.getId()); jobIntentionService.insert(jobIntention); ModelAndView mav = new ModelAndView("redirect:cresume.do?id="+bean.getId()); return mav; }
前台jsp表单中的字段为两个对象的所有字段,如果两个对象中有相同的字段,只设置一个就可以,假如需要不同的值,可以单独设置该字段的值,controller中接收方法也须改动,
public ModelAndView doAdd(JobResume bean,JobIntention jobIntention,@RequestParam("id") Integer id) { //TODO 业务代码 //单独处理id值 }
//方法中的 @RequestParam("id") Integer id 可以是单个,也可以是多个,根据业务需求设置
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: ASP.NET MVC 表单验证方式总结
- 下一篇: C++类的自动转换和强制转换详解和实现