美文网首页
spring-data jpa

spring-data jpa

作者: EnchantF | 来源:发表于2019-06-14 16:40 被阅读0次

    官方文档地址

    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(…);
    }
    

    相关文章

      网友评论

          本文标题:spring-data jpa

          本文链接:https://www.haomeiwen.com/subject/fyfpfctx.html