spring mvc 繫結兩個物件進行表單提交
阿新 • • 發佈:2019-01-23
//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 可以是單個,也可以是多個,根據業務需求設定