Files
bill-java/src/main/java/net/alawn/bill/repository/BookRepo.java
T
2019-05-30 21:17:08 +08:00

28 lines
804 B
Java

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<Book, Long> {
List<Book> 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);
}