【问题标题】:Spring Data Pagination works incorectSpring Data Pagination 工作不正确
【发布时间】:2022-01-05 20:55:12
【问题描述】:

我正在尝试使用分页从我的存储库中获取数据,但结果很奇怪。

控制器代码:

@GetMapping("/warehouses")
@Cacheable(value = "warehouses")
public List<Warehouse> findWarehouses(@RequestParam(name = "page", required = false, defaultValue = "1") int page,
                                      @RequestParam(name = "size", required = false, defaultValue = "10") int size) {
    return warehouseRepository.findAll(PageRequest.of(page, size)).getContent();
}

Repository 使用默认的 MongoRepository 方法。

我正在发送请求并获得下一个结果。 1st query2nd query3rd query4th query5th query6th query

这是我存储在 db 中的数据

[
  {
    _id: 'Compluter Inc',
    merchandiseQuantity: { computer: 16, vacine: 10, bebra: 6 },
    position: { x: 43, y: 12 },
    _class: 'com.logistic.project.model.Warehouse'
  },
  {
    _id: 'Bebra',
    merchandiseQuantity: { grivna: 20, laptop: 100, beer: 1 },
    position: { x: 21, y: 89 },
    _class: 'com.logistic.project.model.Warehouse'
  },
  {
    _id: 'LG',
    merchandiseQuantity: { chair: 90, cup: 13, notebook: 18 },
    position: { x: 15, y: 90 },
    _class: 'com.logistic.project.model.Warehouse'
  },
  {
    _id: 'Abchihba',
    merchandiseQuantity: { gun: 54, computer: 4, answer: 42 },
    position: { x: 567, y: 890 },
    _class: 'com.logistic.project.model.Warehouse'
  },
  {
    _id: 'Node',
    merchandiseQuantity: { grinva: 6, gun: 16, charger: 132 },
    position: { x: 389, y: 54 },
    _class: 'com.logistic.project.model.Warehouse'
  },
  {
    _id: 'Meta',
    merchandiseQuantity: { computer: 16, vacine: 10, bebra: 6 },
    position: { x: 321, y: 590 },
    _class: 'com.logistic.project.model.Warehouse'
  } 
]

感谢您的回答)

【问题讨论】:

  • 我也尝试删除 @Cacheable 并得到相同的结果。

标签: java spring-boot pagination spring-data


【解决方案1】:

没问题我忘了分页是从0开始的

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-01
    • 2019-04-28
    • 2016-05-31
    • 1970-01-01
    • 2016-10-04
    • 2015-11-02
    • 2015-04-20
    相关资源
    最近更新 更多