Skip to content

Commit

Permalink
优化分页结果包装类的泛型参数
Browse files Browse the repository at this point in the history
  • Loading branch information
章福来 authored and abel533 committed May 23, 2022
1 parent ab7f661 commit f2d1889
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/github/pagehelper/PageInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public PageInfo() {
*
* @param list
*/
public PageInfo(List<T> list) {
public PageInfo(List<? extends T> list) {
this(list, DEFAULT_NAVIGATE_PAGES);
}

Expand All @@ -130,7 +130,7 @@ public PageInfo(List<T> list) {
* @param list page结果
* @param navigatePages 页码数量
*/
public PageInfo(List<T> list, int navigatePages) {
public PageInfo(List<? extends T> list, int navigatePages) {
super(list);
if (list instanceof Page) {
Page page = (Page) list;
Expand Down Expand Up @@ -162,11 +162,11 @@ public PageInfo(List<T> list, int navigatePages) {
}
}

public static <T> PageInfo<T> of(List<T> list) {
public static <T> PageInfo<T> of(List<? extends T> list) {
return new PageInfo<T>(list);
}

public static <T> PageInfo<T> of(List<T> list, int navigatePages) {
public static <T> PageInfo<T> of(List<? extends T> list, int navigatePages) {
return new PageInfo<T>(list, navigatePages);
}

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/github/pagehelper/PageSerializable.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ public class PageSerializable<T> implements Serializable {
public PageSerializable() {
}

public PageSerializable(List<T> list) {
this.list = list;
@SuppressWarnings("unchecked")
public PageSerializable(List<? extends T> list) {
this.list = (List<T>) list;
if(list instanceof Page){
this.total = ((Page)list).getTotal();
this.total = ((Page<?>)list).getTotal();
} else {
this.total = list.size();
}
}

public static <T> PageSerializable<T> of(List<T> list){
public static <T> PageSerializable<T> of(List<? extends T> list){
return new PageSerializable<T>(list);
}

Expand Down

0 comments on commit f2d1889

Please sign in to comment.