2017-04-14 6 views
1

PagingAndSortingRepositoryではなくJpaRepositoryを使用してオブジェクトのページを返すメソッドを実装するにはどうすればよいですか?jpaを使用したスプリングブートによるページ設定

マイリポジトリ

public interface GroupRepository extends JpaRepository<Group, Long> { 
    @Query(value = "SELECT g FROM Group") 
    Page<Group> listAllByPage(Pageable pageable); 
} 

私のサービスの実装:

@Override 
public 
Page<Group> findGroupesByPagination(Pageable pageable) { 
    return groupeRepository.listAllByPage(pageable); 
} 

は、私の残りのコントローラの方法:

@RequestMapping(value="/groups", method = RequestMethod.GET) 
public @ResponseBody Page<Group> list(Pageable pageable){ 
    Page<Group> groupes = groupeServiceImpl.findGroupesByPagination(pageable); 
    return groupes; 
} 

は最後に、私はこのエラーを得た:

Error creating bean with name 'groupServiceImpl': Unsatisfied dependency expressed through field 'groupeRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'groupRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract org.springframework.data.domain.Page rimtrack.org.repository.GroupRepository.listAllByPage(org.springframework.data.domain.Pageable)!

+1

選択クエリで「グループ」の後に「G」を追加してください:「グループGからGを選択し、」 – Cepr0

+0

はいおかげで、これが正しい答え – Elouafi

+0

である私を+1することを忘れないでください。コメント;) – Cepr0

答えて

1

The query can be defined by an annotation somewhere or declared by other means. Consult the documentation of the specific store to find available options for that store. If the repository infrastructure does not find a declared query for the method at bootstrap time, it fails.

Spring Data Jpaメソッドを使用する必要があります。 Reference

Page<T> findAll(Pageable pageable); 

リポジトリクラスを変更してください。

試験:

public interface GroupRepository extends JpaRepository<Group, Long> { 
    Page<Group> findAlll(Pageable pageable); 
} 
+0

あなたの応答に感謝しますが、私は何をしたらいいのですか?同じエラーが発生しました – Elouafi

+0

完全なスタックトレースを書いてください。 – ozgur

+0

完全なスタックトレースとはどういう意味ですか? #jackk ?? – Elouafi

関連する問題