20250808优化-单体电池优化

This commit is contained in:
2025-08-13 23:41:34 +08:00
parent 76d0634ae8
commit ff058dceaf
7 changed files with 120 additions and 10 deletions

View File

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