MyBatis环境下PageHelper插件的使用

1、如果项目是Maven构建的,那就很方便了,PageHelper首先引入包依赖:

<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.6</version>
</dependency>

如果不是Maven项目,需要引入PageHelper的jar包到项目中。


2、MyBatis配置文件中进行配置:

<plugins>
<!-- com.github.pagehelper为PageHelper类所在包名 -->
<plugin interceptor="com.github.pagehelper.PageHelper">
<!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->
<property name="dialect" value="mysql"/>
</plugin>
</plugins>

3、使用插件:

// 在进行数据库查询的代码前面加上下面的语句
PageHelper.startPage(pageNum,pageSize);
List<Hospital> hospitalList = hospitalService.findList(hospital);

4、配置完成,开始测试。

来自微信公众号:编程社

程序员日常进阶宝典,欢迎关注!

猜你喜欢

转载自www.cnblogs.com/ai10999/p/11455341.html
今日推荐