如果你在用Mybatis,建议尝试该分页插件,这个一定是最方便使用的分页插件。该插件目前支持Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库分页。
具体配置步骤如下
1、引入jar包,修改javamall.manager.mapper的pom.xml文件
新增如下依赖
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> </dependency>
版本是5.1.11
具体路径如下图所示
2、修改SqlMapConfig.xml文件,新增如下代码
<!-- 配置分页插件 --> <plugins> <plugin interceptor="com.github.pagehelper.PageInterceptor"> </plugin> </plugins>
具体路径如下图所示
简单的2步,分页就配置好了。
注意!如果你的PageHelper用的其他版本的话可能会有类似如下的报错:java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor,点击链接,就能看到解决方法。