package com.estate.expert.admin.domain.common.response;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModelProperty;
|
import lombok.Data;
|
|
|
import java.util.List;
|
|
/**
|
* mybatis plus 分页响应
|
* @param <T>
|
*/
|
@ApiModel("分页响应")
|
@Data
|
public class PageRespMp<T> {
|
|
@ApiModelProperty("总页数")
|
private int totalPages;
|
|
@ApiModelProperty("总记录数")
|
private long totalElements;
|
|
@ApiModelProperty("每页大小")
|
private int pageSize;
|
|
@ApiModelProperty("当前页码, 从0开始")
|
private int number;
|
|
@ApiModelProperty("数据列表")
|
private List<T> list;
|
|
public PageRespMp(Page<?> page, List<T> list) {
|
this.totalPages = (int) page.getPages();
|
this.totalElements = page.getTotal();
|
this.pageSize = (int) page.getSize();
|
this.number = (int) page.getCurrent();
|
this.list = list;
|
}
|
|
public PageRespMp(Page<T> page) {
|
this.totalPages = (int) page.getPages();
|
this.totalElements = page.getTotal();
|
this.pageSize = (int) page.getSize();
|
this.number = (int) page.getCurrent();
|
this.list = page.getRecords();
|
}
|
|
public PageRespMp(List<T> list) {
|
this.list = list;
|
this.totalPages = 1;
|
this.totalElements = list.size();
|
this.pageSize = list.size();
|
this.number = 0;
|
}
|
|
// of
|
public static <T> PageRespMp<T> of(Page<?> page, List<T> list) {
|
return new PageRespMp<>(page, list);
|
}
|
|
// of
|
public static <T> PageRespMp<T> of(Page<T> page) {
|
return new PageRespMp<>(page);
|
}
|
|
// of
|
public static <T> PageRespMp<T> of(List<T> list) {
|
return new PageRespMp<>(list);
|
}
|
|
|
// empty
|
public static <T> PageRespMp<T> empty() {
|
return new PageRespMp<>(new Page<>());
|
}
|
}
|