SpringBoot-Demo-CRUD icon indicating copy to clipboard operation
SpringBoot-Demo-CRUD copied to clipboard

BookController.java 分页查询有点问题

Open AJDX3906 opened this issue 3 years ago • 0 comments

@GetMapping("{currentPage}/{pageSize}")
    public Result getPage(@PathVariable int currentPage,@PathVariable int pageSize,Book book){
        IPage<Book> page = bookService.getPage(currentPage, pageSize,book);
        //如果当前页码值大于总页码数,那么重新执行查询操作,使用最大页码值作为当前页码值。
        if (currentPage > page.getPages()){
            page = bookService.getPage((int)page.getPages(),pageSize);
        }
        return new Result(true,bookService.getPage(currentPage,pageSize,book));
    }

如果是按条件查询,删除字段后当前页码大于总页码,返回的page还是错误的,应该把 if 语句中的 page 返回,要不然条件语句就是摆设。

@GetMapping("{currentPage}/{pageSize}")
    public Result getPage(@PathVariable int currentPage,@PathVariable int pageSize,Book book){
        IPage<Book> page = bookService.getPage(currentPage, pageSize,book);
        if (currentPage > page.getPages()){
            page = bookService.getPage((int)page.getPages(),pageSize,book); //删除后返回的page把条件带上(增加了book条件)
        }
        return new Result(true,page);  //这里返回处理过的page
    }

AJDX3906 avatar Mar 17 '22 03:03 AJDX3906