cn.foxtech.common.entity.utils.PageUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fox-edge-server-common-entity-service Show documentation
Show all versions of fox-edge-server-common-entity-service Show documentation
fox-edge-server-common-entity-service
The newest version!
/* ----------------------------------------------------------------------------
* Copyright (c) Guangzhou Fox-Tech Co., Ltd. 2020-2024. All rights reserved.
* --------------------------------------------------------------------------- */
package cn.foxtech.common.entity.utils;
import cn.foxtech.common.entity.constant.BaseVOFieldConstant;
import cn.foxtech.common.entity.entity.BaseEntity;
import cn.foxtech.common.entity.service.mybatis.BaseEntityMapper;
import cn.foxtech.common.utils.method.MethodUtils;
import cn.foxtech.core.domain.AjaxResult;
import java.util.*;
public class PageUtils {
public static Map getPageList(List entityList, int pageNum, int pageSize) {
Map data = new HashMap<>();
data.put("total", entityList.size());
List resultList = new ArrayList<>();
int pageStartId = pageSize * (pageNum - 1);
int pageEndId = pageSize * pageNum;
int index = 0;
for (Object entity : entityList) {
if (index < pageStartId) {
index++;
continue;
}
if (index >= pageEndId) {
break;
}
resultList.add(entity);
index++;
}
data.put("list", resultList);
return data;
}
/**
* 获得分页列表数据
*
* @param entityList 实体列表
* @param body 包含pageNum和pageSize参数的用户参数
* @return 分页后的数据
*/
public static AjaxResult getPageList(List entityList, Map body) {
try {
Map data = new HashMap<>();
data.put("total", entityList.size());
// 根据ID排序
Collections.sort(entityList, new Comparator() {
public int compare(BaseEntity o1, BaseEntity o2) {
//降序
return o2.getId().compareTo(o1.getId());
}
});
if (body.containsKey(BaseVOFieldConstant.field_page_num) && body.containsKey(BaseVOFieldConstant.field_page_size)) {
List resultList = new ArrayList<>();
int pageNum = Integer.parseInt(body.get(BaseVOFieldConstant.field_page_num).toString());
int pageSize = Integer.parseInt(body.get(BaseVOFieldConstant.field_page_size).toString());
int pageStartId = pageSize * (pageNum - 1);
int pageEndId = pageSize * pageNum;
int index = 0;
for (BaseEntity entity : entityList) {
if (index < pageStartId) {
index++;
continue;
}
if (index >= pageEndId) {
break;
}
resultList.add(entity);
index++;
}
data.put("list", EntityVOBuilder.buildVOList(resultList));
} else {
data.put("list", EntityVOBuilder.buildVOList(entityList));
}
return AjaxResult.success(data);
} catch (Exception e) {
return AjaxResult.error(e.getMessage());
}
}
/**
* 获得分页列表数据
*
* @param entityList 实体列表
* @param body 包含pageNum和pageSize参数的用户参数
* @return 分页后的数据
*/
public static AjaxResult getPageMapList(List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy