gpt4 book ai didi

pagination - Spring 启动: How to configure pagination on a @RepositoryRestResource?

转载 作者:行者123 更新时间:2023-12-04 13:31:48 26 4
gpt4 key购买 nike

我看过thisthis question。但是我仍然无法为存储库方法设置页面调度。不知道我是否受到错误的影响或只是没有正确编写此内容。基本上,我在问是否有人可以提供一个示例,说明如何对通过@RepositoryRestResource批注导出的存储库方法实现分页?

我尝试实现分页

@RepositoryRestResource(collectionResourceRel = "users", path = "users")
public interface UserRepository extends JpaRepository<User, Long> {

Page<User> findByUserGroup(@Param("userGroup") String userGroup,
@Param("page") Pageable pageable);

}

代码生成的错误信息
Offending method public abstract org.springframework.data.domain.Page com.project.repository.UserRepository.findByUserGroup(java.lang.String,java.awt.print.Pageable)

我也尝试过删除pageable的方法参数,然后导致此错误:
Caused by: java.lang.IllegalArgumentException: Either use @Param on all parameters except Pageable and Sort typed once, or none at all!

我在此项目中使用的依赖项。
  • Oracle Java8。
  • “org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE”,
  • “org.springframework.boot:spring-boot-starter-web”,
  • “org.springframework.boot:spring-boot-starter-actuator”,
  • 'org.springframework.boot:spring-boot-starter-mail',
  • “org.springframework.boot:spring-boot-starter-thymeleaf”,
  • “org.springframework.boot:spring-boot-starter-security”,
  • “org.springframework.security.oauth:spring-security-oauth2:2.0.0.RC2”,
  • “org.springframework.boot:spring-boot-starter-data-jpa”,
  • “org.springframework.boot:spring-boot-starter-data-rest”,

  • 任何帮助将不胜感激。

    更新:最终解决方案

    将此添加为其他想知道如何执行此操作的引用。主要区别在于,我必须确保按照所选答案中的说明导入正确的 Pageable对象。
    @RepositoryRestResource(collectionResourceRel = "users", path = "users")
    public interface UserRepository extends JpaRepository<User, Long> {

    Page<User> findByUserGroup(@Param("userGroup") String userGroup, Pageable pageable);

    }

    最佳答案

    您使用的是错误的包中的Pageable类:java.awt.print.Pageable。您应该使用org.springframework.data.domain.Pageable

    关于pagination - Spring 启动: How to configure pagination on a @RepositoryRestResource?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29938977/

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