47 lines
1.4 KiB
Java
47 lines
1.4 KiB
Java
|
|
package com.aida.seller.common.result;
|
||
|
|
|
||
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||
|
|
import lombok.Data;
|
||
|
|
import lombok.NoArgsConstructor;
|
||
|
|
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @ClassName PageResponse
|
||
|
|
* @Description 分页响应
|
||
|
|
*/
|
||
|
|
@Data
|
||
|
|
@NoArgsConstructor
|
||
|
|
@Schema(description = "分页响应结果")
|
||
|
|
public class PageResponse<T> extends Response<List<T>> {
|
||
|
|
@Schema(description = "页码")
|
||
|
|
private long page;
|
||
|
|
@Schema(description = "每页数量")
|
||
|
|
private long size;
|
||
|
|
@Schema(description = "总页数")
|
||
|
|
private long pages;
|
||
|
|
@Schema(description = "总条数")
|
||
|
|
private long total;
|
||
|
|
@Schema(description = "结果集")
|
||
|
|
private List<T> content;
|
||
|
|
|
||
|
|
public PageResponse(Response<List<T>> response, long page, long size, long total, long pages) {
|
||
|
|
if (response != null) {
|
||
|
|
this.setData(response.getData());
|
||
|
|
this.setErrCode(response.getErrCode());
|
||
|
|
this.setErrMsg(response.getErrMsg());
|
||
|
|
}
|
||
|
|
this.page = page;
|
||
|
|
this.size = size;
|
||
|
|
this.total = total;
|
||
|
|
this.pages = pages;
|
||
|
|
this.content = response.getData();
|
||
|
|
}
|
||
|
|
|
||
|
|
public static <T> PageResponse<T> success(IPage<T> page) {
|
||
|
|
Response<List<T>> response = success(page.getRecords());
|
||
|
|
return new PageResponse<>(response, page.getCurrent(), page.getSize(), page.getTotal(), page.getPages());
|
||
|
|
}
|
||
|
|
}
|