Skip to content

Commit

Permalink
Add ListTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
fengwenyi committed Jun 13, 2022
1 parent 549755d commit 592605d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
1 change: 1 addition & 0 deletions LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- 概念变更,响应改为结果,即 Response -> Result
- 对分页返回参数进行调整
- 新增列表模板类 `ListTemplate`

## v2.6.0

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/fengwenyi/api/result/ListTemplate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.fengwenyi.api.result;

import java.io.Serializable;
import java.util.List;

/**
* @author <a href="https://fengwenyi.com">Erwin Feng</a>
* @since 2022-06-13
*/
public class ListTemplate<T> implements Serializable {

private static final long serialVersionUID = 1673060065136736928L;

/** 列表数据 */
private List<T> content;

public List<T> getContent() {
return content;
}

public void setContent(List<T> content) {
this.content = content;
}
}
42 changes: 9 additions & 33 deletions src/main/java/com/fengwenyi/api/result/PageTemplate.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package com.fengwenyi.api.result;

import java.io.Serializable;
import java.util.List;

/**
*
* 分页响应 VO 类 <br><br><br>
* 分页响应类 <br><br><br>
*
* <p>
* 这个类主要是存放分页的一些属性,包含如下字段:
* </p>
*
* <ul>
* <li>{@code current} :当前页</li>
* <li>{@code current} :当前页</li>
* <li>{@code pageSize} :每页显示条数</li>
* <li>{@code totalRows} :总条数 rows</li>
* <li>{@code totalPages} :总页数 - pages</li>
* <li>{@code rows} :数据 - records</li>
* <li>{@code totalRow} :总条数 rows</li>
* <li>{@code totalPage} :总页数</li>
* <li>{@code content} :数据</li>
* </ul>
*
* <p>
Expand All @@ -26,7 +25,7 @@
* @author <a href="https://www.fengwenyi.com">Erwin Feng</a>
* @since 2.7.0
*/
public class PageTemplate<T> implements Serializable {
public class PageTemplate<T> extends ListTemplate<T> {

private static final long serialVersionUID = -4253922988693797927L;

Expand All @@ -50,11 +49,6 @@ public class PageTemplate<T> implements Serializable {
*/
private Long totalPage;

/**
* 数据
*/
private List<T> content;


/**
* 无参数构造方法
Expand All @@ -75,7 +69,7 @@ public PageTemplate(Long current, Integer pageSize, Long totalRow, Long totalPag
this.pageSize = pageSize;
this.totalRow = totalRow;
this.totalPage = totalPage;
this.content = content;
super.setContent(content);
}

/**
Expand Down Expand Up @@ -150,24 +144,6 @@ public PageTemplate<T> setTotalPage(long totalPage) {
return this;
}

/**
* 获取内容
* @return 内容
*/
public List<T> getContent() {
return content;
}

/**
* 设置内容
* @param content 内容
* @return PageResponseVo
*/
public PageTemplate<T> setContent(List<T> content) {
this.content = content;
return this;
}


/**
* PageResponse构造者,可通过该类构造出PageResponseVo
Expand Down Expand Up @@ -235,7 +211,7 @@ public Builder<T> totalPage(long totalPage) {
* @return Builder
*/
public Builder<T> content(List<T> content) {
this.pageTemplate.content = content;
this.pageTemplate.setContent(content);
return this;
}

Expand All @@ -260,7 +236,7 @@ public String toString() {
", pageSize=" + pageSize +
", totalRow=" + totalRow +
", totalPage=" + totalPage +
", content=" + content +
", content=" + getContent() +
'}';
}
}

0 comments on commit 592605d

Please sign in to comment.