@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);

jpa 中的save()方法

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

jpa 中的save()方法

 

相关文章:

  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
  • 2021-10-18
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-26
  • 2021-11-02
  • 2021-10-15
  • 2022-01-07
  • 2022-12-23
相关资源
相似解决方案