mybatis使用pagehelper分頁外掛程式

2021-08-14 10:44:30 字數 817 閱讀 4885

第一步:引入jar

com.github.pagehelper

pagehelper

4.1.6

com.github.jsqlparser

jsqlparser

0.9.1

第二步:在mybatis核心配置檔案mybatis-config.xml中配置外掛程式

interceptor

="com.github.pagehelper.pagehelper"

>

name

="dialect"

value

="mysql"

/>

name

="rowboundswithcount"

value

="true"

/>

第三步:sqlsession呼叫dao之前設定分頁資料

//獲取sqlsessionfactory物件

sqlsessionfactory sqlsessionfactory=new sqlsessionfactorybuilder().build(resourceasstream);

//獲取sqlsession物件

sqlsession sqlsession = sqlsessionfactory.opensession();

pagehelper.startpage(2

,2);

//動態**獲取dao層物件

listusers = userdao.queryalluser();

關於Mybatis的分頁外掛程式pageHelper

1.pagehelper.startpage page,size com.github.pagehelper 查詢後可用new pageinfo 來接 為實體類的list 若只需要list中某個屬性值,則可以將其抽出乙個新的list 物件.stream map get x collect colle...

MyBatis使用細節

1.錯誤 with a primitive return type int 原因 返回值型別為int,但是查詢出來的結果有空值 null 無法轉換成基本型別。包括char,long,short都有可能。select case when select provinceid from kdmc t pr...

Mybatis學習使用

mybatis配置檔案中遇到的一些問題 typealiases typealiases 在以上的配置資訊中,typealiases元素中的配置的作用等同於 寫了之後可以在寫sql配置檔案例如標籤中的屬性就可以不用寫實體的具體路徑直接用別名就可以了,可以簡化 給你看個例子 沒有別名這樣寫寫了別名就可以...