电影网站增删改查-7 spring boots/MVC/neo4j/thymeleaf 电影修改

<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";
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值