mybatis分页弱点
mybatis框架虽然功能强大,但实现分页时,比较费劲,一般分为2个步骤:
- 查询 总共记录数
- 根据 总共记录数 ,每页显示的数量,计算出 总共页数
- 查询分页的数据
需要查询2个sql,才能完成分页,如果查询条件改变时,就需要改动2个sql语句
pagehelper介绍
pagehelper分页插件,就是解决mybaits分页的问题
github:https://github.com/pagehelper/Mybatis-PageHelper
介绍文档:https://github.com/pagehelper/Mybatis-PageHelper/blob/master/README_zh.md
使用方法:https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/zh/HowToUse.md
原理
传统方式
详见 链接
pagehelper方式
使用mybatis拦截器,在mybatis执行查询sql语句时,拦截下SQL,然后进行修改,从而实现分页
下载jar包
参见:https://www.malaoshi.top/show_1EF6OWCmbWTK.html
ssm框架使用(非maven工程)
参见链接:
https://www.malaoshi.top/show_1EF6OWCmbWTK.html
springboot使用pagehelper分页插件
https://www.malaoshi.top/show_1IXGyvQ6l0x.html
