Mybatis中怎么使用pagehelper分頁插件

本篇文章為大家展示了Mybatis中怎么使用pagehelper分頁插件,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

文縣網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),文縣網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為文縣上千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設(shè)要多少錢,請找那個售后服務(wù)好的文縣做網(wǎng)站的公司定做!

1.添加maven依賴

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

2.在 Spring 配置文件中配置攔截器插件,也可以在mybatis的xml里面配置,但是兩種配置不能同時出現(xiàn),否則容易出現(xiàn)com.github.pagehelper.PageInterceptor插件出現(xiàn)空指針問題

在spring.xml中定義:

<!--配置SqlSessionFactory對象 -->  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">    <property name="dataSource" ref="dataSource" />    <property name="configLocation" value="classpath:mybatis-config.xml" />    <property name="typeAliasesPackage" value="com.aoChine.model.entity" />    <property name="mapperLocations" value="classpath:mapper/*.xml" />    <!-- 配置mybatis分頁插件PageHelper -->    <property name="plugins">      <array>        <bean class="com.github.pagehelper.PageInterceptor">          <property name="properties">            <!-- 什么都不配,使用默認(rèn)的配置 -->            <value></value>          </property>        </bean>      </array>    </property>  </bean>

在mybatis-config.xml中定義

<plugins>    <!-- com.github.pagehelper為PageHelper類所在包名 -->    <plugin interceptor="com.github.pagehelper.PageInterceptor">      <!-- 使用MySQL方言的分頁 -->      <property name="helperDialect" value="sqlserver"/><!--如果使用mysql,這里value為mysql-->      <property name="pageSizeZero" value="true"/>    </plugin> </plugins>

3.使用

a)寫正常查詢語句的接口

接口:

b)在service層調(diào)用接口,實(shí)現(xiàn)分頁。

上述內(nèi)容就是Mybatis中怎么使用pagehelper分頁插件,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)站欄目:Mybatis中怎么使用pagehelper分頁插件
標(biāo)題URL:http://muchs.cn/article2/ipjpoc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站商城網(wǎng)站、做網(wǎng)站、微信公眾號用戶體驗(yàn)、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)