比较简单,不废话,直接上代码
首先引入maven依赖
自己封装的PageList
@ApiModel
@Data
public class PageList
private static final long serialVersionUID = 1412759446332294208L;
@ApiModelProperty(value = "每页数量")
private int pageSize;
@ApiModelProperty(value = "当前页")
private int curPage;
@ApiModelProperty(value = "数据总条数")
private long totalCount;
@ApiModelProperty(value = "总页数")
private int totalPage;
@ApiModelProperty(value = "数据LIST")
private List
@ApiModelProperty(value = "数据合计")
private Object dataTotal;
public PageList() {
}
public PageList(int curPage, int pageSize, long totalItems) {
this.curPage = curPage;
this.pageSize = pageSize;
this.totalCount = totalItems;
this.totalPage = (int) Math.ceil((double) totalItems / pageSize);
}
public PageList(PageInfo page) {
this.list.addAll(page.getList());
this.totalCount = (int) page.getTotal();
this.pageSize = (int) page.getSize();
this.curPage = (int) page.getPageNum();
this.totalPage = page.getPages();
}
}
Controller层
@Autowired
private TestService testService;
/**
* 分页查询列表
* @param page
* @param pageSize
* @return
*/
@PostMapping(value = "getPageList")
public PageList
IPage
PageList
new Long(pageInfo.getSize()).intValue(), pageInfo.getTotal());
pageList.setList(pageInfo.getRecords());
return pageList;
}
Service层
public interface TestService {
IPage
}
ServiceImpl层
@Autowired
private TestMapper testMapper;
@Override
public IPage
Page
List
page.setRecords(result);
return page;
}
mapper层代码暂时就不写在这了,都是sql语句,结合以上结构,添加自己业务的参数进去即可
PS:TestVo为自己要返回的实体类对象