1.maven配置分页插件
<! - 分页插件 - > <dependency> <groupId> com.github.pagehelper </ groupId> <artifactId> pagehelper </ artifactId> <version> 3.4.2 </ version> </ dependency>
2.Constant中设置常量,每页要显示的记录数
public static int PAGESIZE = 5;
3.mapper接口和映射文件
/** * 查询全部学生或者根据姓名和班级查询 * @param student 学生对象 * @return 查询到的学生列表 */ List<Student> getStus(Student student);
4.service接口和实体类
【注意】startPage方法之后要紧跟进行分页的SQL语句
@Override public List<Student> getStus(int pageIndex, int pageSize, Student student) { /** * 1.进行分页处理 * 2.显示第pageIndex页的pageSize条数据 * 3.在查询之前执行PageHelper的startPage方法之后紧跟要进行分页的查询语句 */ PageHelper.startPage(pageIndex,pageSize); List<Student> lists = studentMapper.getStus(student); return lists; }
5.handler
【注意】
- 入参:pageIndex
- pageIndex的设置
- pageInfo用来保存数据
- modelAndView
@RequestMapping(