后端
public Page<codesection> pageAll(int num, int size) {
Pageable pageable = PageRequest.of(num,size);
Page<codesection> codesections = codesectionDao.findAll(pageable);
List<codesection> codesectionslist = codesections.getContent();
for (int i = 0; i < codesectionslist.size(); i++) {
codesectionslist.get(i).setFactoryname(factoryinfoDao.findByFactoryid(codesectionslist.get(i).getFactoryid()).getFactoryname());
codesectionslist.get(i).setLinename(lineinfoDao.findByLineid(codesectionslist.get(i).getLineid()).getLinename());
}
int start = 0;
int end = codesectionslist.size();
Page<codesection> klassPage = new PageImpl<codesection>(codesectionslist.subList(start, end), pageable, codesections.getTotalElements());
return klassPage;
}
前端
<div class="pagination">
<el-pagination
background
layout="total, prev, pager, next"
:current-page="query.pageIndex"
:page-size="query.pageSize"
:total="pageTotal"
@current-change="handleCurrentChange"
style="position: fixed;bottom: 20px;"
></el-pagination>
</div>
data() {
return {
query:{
pageIndex:0,
pageSize:9,
},
pageTotal: 0,
}
},
created() {
this.getData(this.query.pageIndex,this.query.pageSize)
},
getData(currentPage,pageSize){
this.axios({
method:'GET',
url:'/page/'+currentPage+'/'+pageSize,
})
.then(res =>{
console.log(res)
this.codes = res.data.content;
this.pageTotal = res.data.totalElements;
})
},
handleCurrentChange(value){
this.query.pageIndex = value;
this.getData(this.query.pageIndex-1,this.query.pageSize);
}