How to use projection interfaces with pagination in Spring Data JPA?

后端 未结 6 2107
-上瘾入骨i
-上瘾入骨i 2021-02-19 10:50

I\'m trying to get a page of a partial entity (NetworkSimple) using the new feature of spring data, projections

I\'ve checked the documentation and if I request only:

6条回答
  •  伪装坚强ぢ
    2021-02-19 11:42

    Even with spring-data-jpa 1.11.4, something like

    public interface NetworkRepository extends JpaRepository {
        Page findAll(Pageable pageable);
    }
    

    would not compile; reporting

    findAll(org.springframework.data.domain.Pageable) in NetworkRepository clashes with findAll(org.springframework.data.domain.Pageable) in org.springframework.data.repository.PagingAndSortingRepository
    return type org.springframework.data.domain.Page is not compatible with org.springframework.data.domain.Page
    

    The workaround we found was to rename findAll to findAllBy, e.g.

    public interface NetworkRepository extends JpaRepository {
        Page findAllBy(Pageable pageable);
    }
    

提交回复
热议问题