【发布时间】: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