@Data
public class RequestPage {
private int page;
private int size;
/**
* 初始化分页参数
*/
public RequestPage(Integer page, Integer size) {
this.page = page == null || page < 1 ? 0 : page - 1;
this.size = size == null || size < 1 ? 20 : size;
}
/**
* 对List进行分页处理
*
* @param list list数据集合
* @param pageable 分页信息
* @param <T>
* @return
*/
public static <T> Page<T> listConvertToPage(List<T> list, Pageable pageable) {
int start = pageable.getOffset();
int end = (start + pageable.getPageSize()) > list.size() ? list.size() : (start + pageable.getPageSize());
return new PageImpl<T>(list.subList(start, end), pageable, list.size());
}
}
使用:
public Response getInPutOutPut(Integer page, Integer size, Integer warehouseId, Integer applicationType, String startDate, String endDate) {
List<Application> applications = warehouseService.getInPutOutPut(warehouseId, applicationType, startDate, endDate);
if (applications != null && applications.size() > 0) {
RequestPage requestPage = new RequestPage(page, size);
Pageable pageable = new PageRequest(requestPage.getPage(), requestPage.getSize(), Sort.Direction.DESC, "createDate");
Page<Application> applicationPage = RequestPage.listConvertToPage(applications, pageable);
return ResponseUtil.success(applicationPage);
}
return ResponseUtil.error(ReturnMsg.NO_DATA);
}
最后
以上就是深情台灯最近收集整理的关于将List
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复