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的數據

