Spring 页面的totalElements 和totalPages 值不正确
我的数据库中有 21 行,我正在使用 Spring 的 Page 来获取它们。
如果我指定的页面大小小于22,它将显示totalElements: 3864,并且totalPages也是错误的。可能出什么问题了?
例子: GET myurl.com/foo?size=5
产生如下结果
{
"content": [
{
{ "pretend_that": "there are five elements here" }
}
],
"pageable": {
"sort": {
"empty": true,
"sorted": false,
"unsorted": true
},
"offset": 0,
"pageNumber": 0,
"pageSize": 5,
"paged": true,
"unpaged": false
},
"last": false,
"totalPages": 773,
"totalElements": 3864,
"size": 5,
"number": 0,
"sort": {
"empty": true,
"sorted": false,
"unsorted": true
},
"first": true,
"numberOfElements": 5,
"empty": false
}
示例 2:
GET myurl.com/foo?size=50
结果
{
"content": [
{
{ "pretend_that": "there are 21 elements here" }
}
],
"pageable": {
"sort": {
"empty": true,
"sorted": false,
"unsorted": true
},
"offset": 0,
"pageNumber": 0,
"pageSize": 50,
"paged": true,
"unpaged": false
},
"last": true,
"totalPages": 1,
"totalElements": 21,
"size": 50,
"number": 0,
"sort": {
"empty": true,
"sorted": false,
"unsorted": true
},
"first": true,
"numberOfElements": 21,
"empty": false
}
产生如下 如果我得到最后一页,它会正确显示页面和元素计数。
我尝试过更改 Spring Boot 版本,但没有帮助。
I have 21 rows in a database and I am using Spring's Page to get them.
If I specify a page size less than 22, it will show totalElements: 3864 and totalPages is also wrong. What could be wrong?
Example:GET myurl.com/foo?size=5
yields a result like this
{
"content": [
{
{ "pretend_that": "there are five elements here" }
}
],
"pageable": {
"sort": {
"empty": true,
"sorted": false,
"unsorted": true
},
"offset": 0,
"pageNumber": 0,
"pageSize": 5,
"paged": true,
"unpaged": false
},
"last": false,
"totalPages": 773,
"totalElements": 3864,
"size": 5,
"number": 0,
"sort": {
"empty": true,
"sorted": false,
"unsorted": true
},
"first": true,
"numberOfElements": 5,
"empty": false
}
Example 2:
GET myurl.com/foo?size=50
yields a result like this
{
"content": [
{
{ "pretend_that": "there are 21 elements here" }
}
],
"pageable": {
"sort": {
"empty": true,
"sorted": false,
"unsorted": true
},
"offset": 0,
"pageNumber": 0,
"pageSize": 50,
"paged": true,
"unpaged": false
},
"last": true,
"totalPages": 1,
"totalElements": 21,
"size": 50,
"number": 0,
"sort": {
"empty": true,
"sorted": false,
"unsorted": true
},
"first": true,
"numberOfElements": 21,
"empty": false
}
P.S. if I get the final page, it shows the page and elements count correctly.
I have tried changing Spring Boot versions and that hasn't helped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论