gpt4 book ai didi

java - 使用 jpa 通过 spring boot 进行分页

转载 作者:行者123 更新时间:2023-11-30 02:34:41 25 4
gpt4 key购买 nike

如何实现使用 JpaRepository 而不是 PagingAndSortingRepository 返回对象页面的方法?

我的存储库

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

我的休息 Controller 方法:

@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)!

最佳答案

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

关于java - 使用 jpa 通过 spring boot 进行分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43408618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com