This commit is contained in:
小久哥
2022-06-07 16:10:59 +08:00
parent e3843fdad8
commit 8503e7a69f
22 changed files with 434 additions and 91 deletions
+6
View File
@@ -127,6 +127,12 @@
<groupId>com.alibaba</groupId>
<artifactId>transmittable-thread-local</artifactId>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.3.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
@@ -0,0 +1,98 @@
package cn.iocoder.yudao.framework.common.page;
import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.experimental.UtilityClass;
import java.util.ArrayList;
import java.util.List;
/**
* 分页工具类
*
* @author xggz <yyimba@qq.com>
* @since 2021/6/4 11:50
*/
@UtilityClass
public class PageUtil<T> {
/**
* 转换PageHelper插件的分页数据
*
* @param pageInfo
* @param <T>
* @return
*/
public <T> PageVO<T> convertPageInfo(PageInfo<T> pageInfo) {
return BeanUtil.copyProperties(pageInfo, PageVO.class);
}
/**
* 转换PageHelper插件的分页数据
*
* @param list
* @param <T>
* @return
*/
public <T> PageVO<T> convertPageInfo(List<T> list) {
return BeanUtil.copyProperties(new PageInfo<T>(list), PageVO.class);
}
/**
* 复制分页数据
*
* @param sourcePage
* @param results
* @param <T>
* @return
*/
public <T> PageVO<T> copyPage(Object sourcePage, List<T> results) {
PageVO<T> targetPage = BeanUtil.copyProperties(sourcePage, PageVO.class);
targetPage.setList(results);
return targetPage;
}
/**
* 返回空白的分页对象
*
* @param pageNum
* @param pageSize
* @param dataClass
* @param <T>
* @return
*/
public <T> PageVO<T> emptyPage(Integer pageNum, Integer pageSize, Class<T> dataClass) {
PageVO page = new PageVO<>();
page.setPageNum(pageNum);
page.setPageSize(pageSize);
page.setSize(0);
page.setPages(0);
page.setTotal(0);
page.setHasNextPage(false);
page.setHasPreviousPage(false);
page.setList(new ArrayList());
return page;
}
/**
* 返回空白的分页对象
*
* @param pageDTO
* @param dataClass
* @param <T>
* @return
*/
public <T> PageVO<T> emptyPage(PageDTO pageDTO, Class<T> dataClass) {
return emptyPage(pageDTO.getPageNum(), pageDTO.getPageSize(), dataClass);
}
/**
* 使用PageHelper设置分页参数
*
* @param pageDTO
*/
public void startPage(PageDTO pageDTO) {
PageHelper.startPage(pageDTO.getPageNum(), pageDTO.getPageSize());
}
}
@@ -0,0 +1,45 @@
package cn.iocoder.yudao.framework.common.page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 分页结果
*
* @author xggz <yyimba@qq.com>
* @since 2021/6/4 10:53
*/
@Data
@ApiModel(value = "PageVO", description = "分页结果")
public class PageVO<T> implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("当前页")
private int pageNum;
@ApiModelProperty("每页的数量")
private int pageSize;
@ApiModelProperty("当前页的数量")
private int size;
@ApiModelProperty("总页数")
private int pages;
@ApiModelProperty("是否有前一页")
private boolean hasPreviousPage = false;
@ApiModelProperty("是否有后一页")
private boolean hasNextPage = false;
@ApiModelProperty("总记录数")
private long total;
@ApiModelProperty("结果集")
private List<T> list;
}