Spring Data JPA ---改

1.直接調用save方法

 

2.自定義 參考 How do I update an entity using spring-data-jpa?

@Query:自定義sql

@Modifying:告訴spring-data-jps  這個sql是更新操作,需要用 executeUpdate() 而不是 executeQuery().

@Repository
public interface FruitRepository extends JpaRepository<Fruit, Long> {
    @Modifying
    @Query("update Fruit f set f.name=:name  where f.color=:color")
    void updateFruits(@Param("name") String name, @Param("color") String color);
}

返回值
int : the number of records being updated.
boolean : true if there is a record being updated. Otherwise, false.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章