@Data @ToString @Builder @AllArgsConstructor public class PageResult<T> implements Serializable { private List<T>items; private long counts; private long page; private long pageSize; }
上述为一个简单的实体类,接下来我们需要通过建造者模式构建他
PageResult pageResult1=PageResult.builder() .items(courseBaseIPage.getRecords()) .counts(courseBaseIPage.getTotal()) .page(courseBaseIPage.getPages()) .pageSize(courseBaseIPage.getSize()) .build();
按照提示修改完成之后
PageResult pageResult1=PageResult.builder() .items(Collections.singletonList(courseBaseIPage.getRecords())) .counts(courseBaseIPage.getTotal()) .page(courseBaseIPage.getPages()) .pageSize(courseBaseIPage.getSize()) .build();
通过上述做法会使records再加上一层[ ],即本来是item= [ ],而现在则是item=[ [ ] ],那么如何保持item=[ ]?
使用T的正确做法
PageResult pageResult1=PageResult.<CourseBase>builder() .items(courseBaseIPage.getRecords()) .counts(courseBaseIPage.getTotal()) .page(courseBaseIPage.getPages()) .pageSize(courseBaseIPage.getSize()) .build();
标签:返回,正确,pageSize,private,Bulider,courseBaseIPage,counts,PageResult,page From: https://www.cnblogs.com/kun1790051360/p/18240499