PageHelper使用


之前我们整合过SSM框架,可以查询数据库数据,项目中一般不会全部查询所有数据,为了美观和性能,都是采用分页形式查询数据

一:pom.xml导入pagehelper.jar

<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.10</version>
</dependency>

二:在 MyBatis 配置 xml 中配置拦截器插件

之前我们没有单独的mybatis配置文件,都是集成在applicationContext.xml中的,现在我们需要重新创建新的mybatis配置文件

 

 

三:在applicationContext.xml中引入该文件并配置

 

 

 

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 注意其他配置 --> <property name="plugins"> <array> <bean class="com.github.pagehelper.PageInterceptor"> <property name="properties"> <!--使用下面的方式配置参数,一行配置一个 --> <value> params=value1 </value> </property> </bean> </array> </property> </bean>

四:在代码中使用


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM