<a class="c-50a73f mlr-6" href="javascript:void(0)" οnclick="edit(\''+ v.id+'\')">修改</a>
通过jquery HTTP get 方法:
function edit(id){ $.get("./edit/"+id,{ts:new Date().getTime()},function(data){ art.dialog({ lock:true, opacity:0.3, title: "修改", width:'750px', height: 'auto', left: '50%', top: '50%', content:data, esc: true, init: function(){ artdialog = this; }, close: function(){ artdialog = null; } });//artDialog是一个基于javascript编写的对话框组件 }); }
调用 controller :
@RequestMapping(value="/edit/{id}") public ModelAndView update(ModelMap model, @PathVariable Long id){ Movie movie = movieRepository.findOne(id); String[] files = {"/images/movie/西游记.jpg","/images/movie/西游记续集.jpg"}; String[] rolelist = new String[]{"唐僧","孙悟空","猪八戒","沙僧"}; Iterable<Actor> actors = actorRepository.findAll(); model.addAttribute("files", files); model.addAttribute("rolelist",rolelist); model.addAttribute("movie",movie); model.addAttribute("actors",actors); return new ModelAndView("movie/edit"); }这里编辑电影相当于新增演员角色等功能
@RequestMapping(method = RequestMethod.POST, value="/update") public String update(Movie movie, HttpServletRequest request) throws Exception{ String rolename = request.getParameter("rolename"); String actorid = request.getParameter("actorid"); Movie old = movieRepository.findOne(movie.getId()); old.setName(movie.getName()); old.setPhoto(movie.getPhoto()); old.setCreateDate(movie.getCreateDate()); if(!StringUtils.isEmpty(rolename) && !StringUtils.isEmpty(actorid)) { Actor actor = actorRepository.findOne(new Long(actorid)); old.addRole(actor, rolename); } movieRepository.save(old); logger.info("修改->ID="+old.getId()); return "1"; }