1. 程式人生 > 遊戲攻略 >《原神攻略》2.6版雷八班菱超載隊配置推薦

《原神攻略》2.6版雷八班菱超載隊配置推薦

spring使用jpa進行update操作主要有兩種方式:

1、呼叫儲存實體的方法

1)儲存一個實體:repository.save(T entity)

2)儲存多個實體:repository.save(Iterable<T> entities)

3)儲存並立即重新整理一個實體:repository.saveAndFlush(T entity)

注:若是更改,entity中必須設定了主鍵欄位,不然不能對應上資料庫中的記錄,變成新增(資料庫自動生成主鍵)或報錯(資料庫不自動生成主鍵)了

2、@Query註解,自己寫JPQL語句

使用JPA中@Query 註解實現update 操作,程式碼如下:

@Transactional
@Modifying(clearAutomatically = true)
 @Query(value = "update StockOut sc set sc.receivedPersonId=?1,sc.receivedPerson=?2,sc.receivedDate=?3 where stockOutCode=?4")
 int receipt(Long uid,  String uname, Date createDate, String soCode);

備註: 1.更新StockOut表下一些欄位, 這裡使用了不是原生的sql語句,所以不要加nativeQuery = true。

2.@Transactional 註解用於提交事務,若沒有帶上這句,會報事務異常提示。 3.@Modifying(clearAutomatically = true) 自動清除實體裡儲存的資料。