Mybatis分頁外掛程式,mybatis分頁

來源:互聯網
上載者:User

Mybatis分頁外掛程式,mybatis分頁
1.說明

如果你也在用Mybatis,建議嘗試該分頁外掛程式,這個一定是最方便使用的分頁外掛程式。

該外掛程式目前支援Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六種資料庫分頁。

 

 

2.使用方法

第一步:在Mybatis配置xml中配置攔截器外掛程式:

<plugins>    <!-- com.github.pagehelper為PageHelper類所在包名 -->    <plugin interceptor="com.github.pagehelper.PageHelper">        <!-- 設定資料庫類型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六種資料庫-->                <property name="dialect" value="mysql"/>    </plugin></plugins>

 

第二步:在代碼中使用

1、設定分頁資訊:

//擷取第1頁,10條內容,預設查詢總數countPageHelper.startPage(1, 10); //緊跟著的第一個select方法會被分頁List<Country> list = countryMapper.selectIf(1);

2、取分頁資訊

//分頁後,實際返回的結果list類型是Page<E>,如果想取出分頁資訊,需要強制轉換為Page<E>,Page<Country> listCountry = (Page<Country>)list;listCountry.getTotal();

3、取分頁資訊的第二種方法

//擷取第1頁,10條內容,預設查詢總數countPageHelper.startPage(1, 10);List<Country> list = countryMapper.selectAll();//用PageInfo對結果進行封裝PageInfo page = new PageInfo(list);//測試PageInfo全部屬性//PageInfo包含了非常全面的分頁屬性assertEquals(1, page.getPageNum());assertEquals(10, page.getPageSize());assertEquals(1, page.getStartRow());assertEquals(10, page.getEndRow());assertEquals(183, page.getTotal());assertEquals(19, page.getPages());assertEquals(1, page.getFirstPage());assertEquals(8, page.getLastPage());assertEquals(true, page.isFirstPage());assertEquals(false, page.isLastPage());assertEquals(false, page.isHasPreviousPage());assertEquals(true, page.isHasNextPage());

  

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.