如何将ArrayList转换为Pageable对象springboot

时间:2018-11-04 04:47:14

标签: java angular spring-mvc spring-boot

我试图将列表作为页面对象返回给我的客户端角度应用程序。但是它返回所有列表而不是页面。

  

这是我的服务器端控制器方法,它返回列表

    @GetMapping("/users/departmentAdminPageUsers")
    @Timed
    public ResponseEntity<List<DepartmentAdminPageUserDTO>> getDepartmentAdminPageUsers(@ApiParam Pageable pageable, @ApiParam String searchKey, @ApiParam String depId)
        throws URISyntaxException {
        List<DepartmentAdminPageUserDTO> userList=userService.getAllDepartmentAdminPageUsers(depId,searchKey);
        final Page<DepartmentAdminPageUserDTO> page = new PageImpl<>(userList, pageable,userList.size());
        HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/users/departmentAdminPageUsers");
        return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);

    }   
  

这是我发送请求的客户端角度方法

getAllUsersByDepId(req?: any):Observable<Response>{
        let params: URLSearchParams = new URLSearchParams();
        if (req) {
            params.set('page', req.page);
            params.set('size', req.size);
            params.set('searchKey', req.searchKey);
            params.set('depId', req.depId);  
        }
        let options = {
            search: params
        };
        return this.http.get(this.resourceUrl+ '/departmentAdminPageUsers', options);

    }
  

我需要返回页面,而不是整个列表。

1 个答案:

答案 0 :(得分:0)

您要返回整个列表作为页面内容,请尝试:

List<DepartmentAdminPageUserDTO> userSubList = userList.subList((pageable.getPage()-1)*pageable.getSize(), (pageable.getPage()*pageable.getSize())-1);
final Page<DepartmentAdminPageUserDTO> page = new PageImpl<>(userSubList, pageable,userList.size());