如何實現一個方法,使用JpaRepository而不是PagingAndSortingRepository返回一頁對象?分頁與彈簧啓動usiing 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)!
嘗試在選擇查詢「組」後加上「G」:「選擇克來自G組」 – Cepr0
是由於這是一個正確的答案 – Elouafi
不要忘記我的+1評論;) – Cepr0