jpa 中的save()方法

@RequestMapping(value = "", method = RequestMethod.POST)
    public String postAccount(@RequestParam(value = "name") String name,
                              @RequestParam(value = "money") double money) {
        Account account = new Account();
        account.setMoney(money);
        account.setName(name);
        //account.setId(4);
        Account account1 = accountDao.save(account);

如果对应的id不存在,save方法则为insert

将注释 打开,数据库中是存在id=4的对象的

//account.setId(4);

发送请求 http://localhost:8080/account?name=dd&money=77  ,则此处save为更新 id=4的数据

 

posted @ 2018-08-02 16:39  Andrew_F  阅读(3767)  评论(1编辑  收藏  举报