官方文档:如何使用分页插件
1、引入插件
java
<!-- 分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.3.2</version>
</dependency>
2、注册配置文件
java
//mybatis的分页插件组件
@Bean
public PageInterceptor pageInterceptor(){
PageInterceptor pageInterceptor = new PageInterceptor();
Properties properties=new Properties();
properties.setProperty("helperDialect","mysql");
properties.setProperty("reasonable","true");
properties.setProperty("rowBoundsWithCount","true");
pageInterceptor.setProperties(properties);
return pageInterceptor;
}
3、使用
java
@Override
public PageInfo<Student> queryLike(int pageNum, int pageSize,Student student) {
PageHelper.startPage(pageNum,pageSize);
List<Student> students = studentMapper.queryLike(student);
return new PageInfo<Student>(students);
}
java
@RequestMapping (value = "/queryLike",method = RequestMethod.POST)
@ResponseBody
public String queryLikeStudents(int pageSize,int pageNum, String stuNumber, String stuName, String clazz
){
Student student = new Student();
student.setClazz(clazz);
student.setStuName(stuName);
student.setStuNumber(stuNumber);
PageInfo<Student> studentPageInfo = ssi.queryLike(pageNum, pageSize, student);
logger.info("queryLike--studentPageInfo = " + JSON.toJSONStringWithDateFormat(studentPageInfo,"yy-MM-dd"));
return JSON.toJSONStringWithDateFormat(studentPageInfo,"yyyy-MM-dd");
}