20250808优化-单体电池优化
This commit is contained in:
@ -232,4 +232,27 @@ public class BaseController
|
||||
rspData.setTotal(list.size());
|
||||
return rspData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用分页工具方法
|
||||
*/
|
||||
protected <T> List<T> paginateList(List<T> sourceList) {
|
||||
if (sourceList == null || sourceList.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
// 分页梳理
|
||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
||||
int pageNum = pageDomain.getPageNum();
|
||||
int pageSize = pageDomain.getPageSize();
|
||||
int startIndex = 0;
|
||||
int endIndex = sourceList.size();
|
||||
if (pageNum > 0 && pageSize > 0) {
|
||||
// 计算起始索引(处理页码小于1的情况)
|
||||
startIndex = Math.max((pageNum - 1) * pageSize, 0);
|
||||
// 计算结束索引(处理超出列表长度的情况)
|
||||
endIndex = Math.min(startIndex + pageSize, sourceList.size());
|
||||
}
|
||||
// 截取分页数据
|
||||
return sourceList.subList(startIndex, endIndex);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user