1.导入pageHelper依赖,version最好5.1.3以上,不然可能显示返回不了数据
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.4</version>
</dependency>
2.配置mybatis.xml
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<property name="reasonable" value="true"/>
</plugin>
</plugins>
3.controller层调用
@RequestMapping("list")
public String getAll() {
String str = "";
PageHelper.startPage(1,5);
List<Student> list = studentService.findAll();
PageInfo<Student> pageInfo=new PageInfo<>(list);
str=JSONArray.toJSONString(pageInfo);
return str;
}