在layui表格中增加属性page:true
layui默认会传回两个参数,一个是limit,另一个是page;
其中limit是每页的条数,page是标识第几页
然后我们在后台pom.xml中配置pagehelper
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
pagehelper只对最近一句的查询语句生效
所以,在查询之前,加入PageHelper.startPage(page,limit),他就会自动帮我们分页
下面是我自己的后台的例子
@GetMapping("good/all")
@ResponseBody
public resultList getAllGood(int limit,int page){
resultList list=new resultList();
list.setCount(goodService.getTotalNumOfGood());
PageHelper.startPage(page,limit);//这一句是重点
List goodList=goodService.getAllGood();
if(goodList!=null){
list.setData(goodList);
list.setCode(0);
}else{
list.setCode(200);
}
return list;
}