Skip to content
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

分页接口抛出异常时可能会影响正常接口的查询 #1

Closed
Cat7373 opened this issue Mar 21, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@Cat7373
Copy link
Owner

commented Mar 21, 2019

如果分页的接口在执行实际的查询之前就会出现异常,或者压根就没有执行查询,比如这样:

@Pager
@GetMapping("/list")
public Result<List<User>> list() {
    // 一些判断
    if (...) {
        // 抛出异常(或只是返回一个失败的结果)
        throw new RuntimeException("您无权进行查询");
    }

    // 真实的查询,并将其包装成 Result 后返回
    return Result.success(this.userService.listAll());
}

在第一个 if 条件成立时,查询并不会真正的执行,分页设置自然也没有被消耗掉,而当这个线程下次处理其他接口时,这个接口没有被消耗的分页就会被应用到后续的查询当中,从而影响后续的查询

如果这个后续的查询存在分页设置,那么这个没有被消耗的分页设置会被覆盖掉,不会导致任何问题,但如果后续的查询不存在分页设置,这个没有被消耗的分页设置就会生效,最终会导致下次查询出的结果数量可能比正常结果要少

@Cat7373 Cat7373 closed this in 0150594 Mar 21, 2019

Cat7373 added a commit that referenced this issue Mar 21, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.