<!--分页插件 注意版本,要在5.1.2以上-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.8</version>
</dependency>
<!--sql解析包 注意版本,要在1.2以上-->
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>1.2</version>
</dependency>
ServiceImpl
//分页查询所有学生
@Override
public PageInfo<Student> findAllStuPage(int currentPage, int pageSize) {
String orderBy = "CreateDate desc"; //根据时间降序
//装载分页信息
PageHelper.startPage(currentPage, pageSize,orderBy);
//查询到的结果集
List<Student> stus = studentDao.findAllStu();
//获取结果集的分页信息
PageInfo<Student> pageInfo = new PageInfo<>(stus);
//返回结果集
//return studentDao.findAllStu();
return pageInfo;
}
Mapper.xml
<!--查询所有学生-->
<select id="findAllStu" resultType="Student" resultMap="stuMap">
/* select * from student order by {CreateDate} DESC,{ID} DESC;*/
select * from student
</select>
Controller
//查询学生表
PageInfo<Student> allStuPage = studentService.findAllStuPage(Integer.parseInt(pageCode), Integer.parseInt(pageSize));//收到结果集
List<Student> allStu = allStuPage.getList();//从结果集中拿出学生集合