【发布时间】:2015-12-05 21:06:32
【问题描述】:
在我的 Spring MVC 应用程序中,我将 spring-data-jpa 与 MySql 数据库一起使用。 对于试图实现分页的数据表。
表上有191条记录,'id'是主键——从10、11、12开始的值----199、200。
我的每个页面包含假设 10 条记录。
以下是我用来从表中仅获取 10 条记录的代码。
Pageable pageable = new PageRequest(firstResult, maxResults);
Page<User> findAll2 = repository.findAll(pageable);
对于第 1 页 -> firstResult = 1 和 maxResults = 10
Pageable pageable = new PageRequest(1, 10);
这里我得到 10 条记录,id 20 到 29
但我期待从 10 到 19
对于第 2 页 -> firstResult = 11 和 maxResults = 10
Pageable pageable = new PageRequest(11, 10);
这里我得到 10 条记录,id 120 到 129
其他记录呢。
现在
对于第 3 页 ->firstResult = 21 和 maxResults = 10
可分页可分页 = new PageRequest(21, 10);
在这里我没有得到任何记录。
All values are null.Not sure what I am missing.please help me on this.
【问题讨论】: