分页查询Page的getSize与getTotalElements使用对比

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

    开始用到SpringData分页,在跟着资料写项目的时候,看到分页的数量和返回的不一致。

一.使用Page.getSize

    @RequestMapping(value = "/search/{page}/{size}", method = RequestMethod.POST)
    public Result findSearch(@RequestBody Map searchMap,@PathVariable int page,@PathVariable int size) {
        Page

    分页结果:主要是total不同,这里的total不等于当前的rows的大小。

{
    "flag": true,
    "code": 20000,
    "message": "查询成功",
    "data": {
        "total": 9,
        "rows": [
            {
                "id": "3",
                "labelname": "C++",
                "state": "1",
                "count": null,
                "recommend": "2",
                "fans": null
            },
            {
                "id": "4",
                "labelname": "python",
                "state": "1",
                "count": null,
                "recommend": "2",
                "fans": null
            }
        ]
    }
}

 

二.使用Page.getTotalElements

    @RequestMapping(value = "/search/{page}/{size}", method = RequestMethod.POST)
    public Result findSearch(@RequestBody Map searchMap,@PathVariable int page,@PathVariable int size) {
        Page

    我的分页结果:total的值等于rows的大小。

{
    "flag": true,
    "code": 20000,
    "message": "查询成功",
    "data": {
        "total": 2,
        "rows": [
            {
                "id": "3",
                "labelname": "C++",
                "state": "1",
                "count": null,
                "recommend": "2",
                "fans": null
            },
            {
                "id": "4",
                "labelname": "python",
                "state": "1",
                "count": null,
                "recommend": "2",
                "fans": null
            }
        ]
    }
}

 

    暂时先记录一下,两者的区别等项目完成后,看源码找答案。

转载于:https://my.oschina.net/javamaster/blog/2223100

你可能感兴趣的:(分页查询Page的getSize与getTotalElements使用对比)