分页与条件以及页面请求用于设置限制记录时会导致分页错误。

huangapple 未分类评论43阅读模式
英文:

Pagination with Criteria and PageRequest for set limit records brokes Pagination

问题

@GetMapping("/requests")
public ResponseEntity<List<Request>> getAllRequests(RequestCriteria criteria, Pageable pageable) {
    log.debug("REST request to get Requests by criteria: {}", criteria);
    pageable = PageRequest.of(0, recordsLimit);
    Page<Request> page = requestQueryService.findByCriteria(criteria, pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(), page);
    return ResponseEntity.ok().headers(headers).body(page.getContent());
}
英文:

i have problem. I have method @GetMapping for gets all requests from database, but when i want to set limit of records from DB pagination stops working, where i got something wrong ? Without line pageable = PageRequest.... it works fine.

@GetMapping(&quot;/requests&quot;)
    public ResponseEntity&lt;List&lt;Request&gt;&gt; getAllRequests(RequestCriteria criteria, Pageable pageable) {
        log.debug(&quot;REST request to get Requests by criteria: {}&quot;, criteria);
        pageable = PageRequest.of(0,recordsLimit);
        Page&lt;Request&gt; page = requestQueryService.findByCriteria(criteria,pageable);
        HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(), page);
        return ResponseEntity.ok().headers(headers).body(page.getContent());
    }

huangapple
  • 本文由 发表于 2020年7月27日 14:45:57
  • 转载请务必保留本文链接:https://java.coder-hub.com/63110007.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定