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