spring-data jpa
2019-06-14 本文已影响0人
EnchantF
Repository >CrudRepository> PagingAndSortingRepository
JpaRepository
MongoRepository
分页、排序(Pageable, Slice, and Sort)
Page<User> findByLastname(String lastname, Pageable pageable);
Slice<User> findByLastname(String lastname, Pageable pageable);
List<User> findByLastname(String lastname, Sort sort);
List<User> findByLastname(String lastname, Pageable pageable);
限制查询(Top/First)
User findFirstByOrderByLastnameAsc();
User findTopByOrderByAgeDesc();
Page<User> queryFirst10ByLastname(String lastname, Pageable pageable);
Slice<User> findTop3ByLastname(String lastname, Pageable pageable);
List<User> findFirst10ByLastname(String lastname, Sort sort);
List<User> findTop10ByLastname(String lastname, Pageable pageable);
流式查询
@Query("select u from User u")
Stream<User> findAllByCustomQueryAndStream();
Stream<User> readAllByFirstnameNotNull();
@Query("select u from User u")
Stream<User> streamAllPaged(Pageable pageable);
使用流式查询
try (Stream<User> stream = repository.findAllByCustomQueryAndStream()) {
stream.forEach(…);
}