jpa 中的save()方法 如果对应的id不存在,save方法则为insert,如果存在实际执行根据主键update
https://www.cnblogs.com/Andrew520/p/9408057.html
1 2 3 4 5 6 7 8 | @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的数据