如何实现一个方法,使用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