Controller
@RequestMapping(value = "edit/{id}", method=RequestMethod.GET) public ModelAndView edit(@ModelAttribute MyData mydata, @PathVariable int id, ModelAndView mav) { mav.setViewName("edit"); mav.addObject("title","edit mydata."); Optional<MyData> data = repository.findById((long)id); mav.addObject("formModel", data.get()); return mav; } @RequestMapping(value = "edit", method=RequestMethod.POST) @Transactional(readOnly=false) public ModelAndView update(@ModelAttribute MyData mydata, ModelAndView mav) { repository.saveAndFlush(mydata); return new ModelAndView("redirect:/"); }
IDの値があるので、saveAndFlushでupdateされる
うお、Javaでやるとビビるな。なんでだろ〜