Skip to content

BookController.java 分页查询有点问题 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AJDX3906 opened this issue Mar 17, 2022 · 0 comments
Open

BookController.java 分页查询有点问题 #1

AJDX3906 opened this issue Mar 17, 2022 · 0 comments

Comments

@AJDX3906
Copy link

@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
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant