分页插件PageHelper
如果你也在用Mybatis,建议尝试该分页插件,这个一定是最方便使用的分页插件。
该插件目前支持Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库分页
使用方法
添加PageHelper 依赖到工程中
在Mybatis配置xml中配置拦截器插件
<plugins>
<!-- com.github.pagehelper为PageHelper类所在包名 -->
<plugin interceptor="com.github.pagehelper.PageHelper">
<!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->
<property name="dialect" value="mysql"/>
</plugin>
</plugins>
- 获取分页信息
PageHelper.startPage(1, 10);
List<Country> list = countryMapper.selectAll();
//用PageInfo对结果进行包装
PageInfo page = new PageInfo(list);
使用EasyUIDataGridResult 的警告问题
PageInfo回讲数据存到Page对象中,而Page实际上是一个ArrayList。前台使用EasyUIDataGridResult 接受序列化后的page对象,然后将其反序列化为List。因此即使没有Page对象也不会报错,只是报警告。
解决警告:只需要将PageHelper依赖添加到前台即可。
六月 20, 2018 9:14:13 下午 com.alibaba.com.caucho.hessian.io.SerializerFactory getDeserializer
警告: Hessian/Burlap: ‘com.github.pagehelper.Page’ is an unknown class in WebappClassLoader
context:
delegate: false
repositories:
———-> Parent Classloader:
ClassRealm[plugin>org.apache.tomcat.maven:tomcat7-maven-plugin:2.2, parent: sun.misc.Launcher$AppClassLoader@18b4aac2]
:
java.lang.ClassNotFoundException: com.github.pagehelper.Page