package net.alawn.bill.repository; import net.alawn.bill.entity.po.Book; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import java.util.List; /** * @Author: Alawn * @Description: * @Date: Create in 11:14 2019-05-23 */ @Transactional @Repository public interface BookRepo extends JpaRepository { List findByUserId(long userId); @Modifying @Query(value = "update t_bill_books set total_amount = (select sum(amount) from t_bill_items where book_id = ?1) where id = ?1",nativeQuery = true) void sumAmount(long bookId); }