gpt4 book ai didi

java - Spring Boot如何将ArrayList转换为Pageable对象

转载 作者:太空宇宙 更新时间:2023-11-04 10:04:07 26 4
gpt4 key购买 nike

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

this is my server side controller method which return the list

    @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);

}

this is my client side angular method which send request

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);

}

I need to return page instead the whole list.

最佳答案

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

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());

关于java - Spring Boot如何将ArrayList转换为Pageable对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53137831/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com