mybatis使用PageInterceptor插件进行查询分页方法:
pagehelper jar依赖前面这个jar所以两个需要同时引入,才可使用pagehelper
二. mybatis-config.xml配置
三. 调用@RequestMapping(value = "/studentList",method = RequestMethod.GET)
public String studentList(Student student, Model model,
@RequestParam(defaultValue = "1") Integer page,
HttpServletRequest request){
PageHelper.startPage(page,2);//开始分页
List list = studentService.studentAll(student);
PageInfo pageInfo = new PageInfo(list);//封装分页数据
model.addAttribute("studentList",list);
//model.addAttribute("pageInfo",pageInfo);
int total = (int) pageInfo.getTotal(); //页码总数
int size = 2;
int step = 9;
String pages = Pager.getPages(total, size, step, page, request, "page");
model.addAttribute("pages",pages);
return "admin/student/index";
}
四. 视图页面
男 女 |
选择 | ID | 姓名 | 性别 | 爱好 | 时间 | 图片 | 操作 |
${list.id} | ${list.names} | ${list.sex} | ${list.hobby} |
| 删除 修改 | ||
${pages} |
效果如下:
Paper.getPasge见http://www.ncyteng.com/news/show/745.html