首先需要通过maven导入pagehelper分页插件,在pom.xml文件中加入pagehelper依赖;
使用spring时加入以下依赖:
<!-- 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.6</version>
</dependency>
使用springboot是要加入以下依赖:
<!--分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
使用分页插件获取数据:
@RequestMapping("getPageByCondition")
@ResponseBody
public Object getPageByCondition(Invesitagion condition) {
PageHelper.startPage(condition.getPage(), condition.getLimit(), true); //执行分页查询
PageInfo<Invesitagion> pageInfo = new PageInfo<Invesitagion>((Page) infoService.getPageByCondition(condition));//执行查询语句
return new ResultLayuiPage(pageInfo);//返回json数据
}