繁体   English   中英

Spring 数据分页工作不正确

[英]Spring Data Pagination works incorect

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

控制器代码:

@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 方法。

我正在发送请求并获得下一个结果。 第一个查询第二个查询第三个查询第四个查询第五个查询第六个查询

这是我在 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'
  } 
]

感谢您的回答)

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM