Mybatis Limit實現(xiàn)分頁功能
1.1 為什么需要分頁 減少數(shù)據(jù)的處理量
1.2 使用Limit實現(xiàn)分頁
select * from user limit startIndex,pageSize; # 注意是從startIndex+1開始查詢 pageSize 個select * from user limit 3; # [0,3]
1.3 使用mybatis實現(xiàn)分頁(核心:SQL)
1.3.1 接口
UserMapper.java
// limit實現(xiàn)分頁 Map后面只能是 Integer 包裝類 不可以 int List<User> getUserByLimit(Map<String, Integer> map);
1.3.2 UserMapper.xml
<select resultMap='com.tian.pojo.User' parameterType='map'>select *from mybatis.userlimit #{statrIndex},#{pageSize}; </select>
1.3.3 測試類
UserMapperTest.java
<select resultMap='UserMap' parameterType='map'>select *from `mybatis`.`user`limit #{startIndex},#{pageSize}; </select> <select resultMap='UserMap'>select *from `mybatis`.`user`where id = #{id}; </select>
執(zhí)行結(jié)果:

到此這篇關(guān)于Mybatis Limit實現(xiàn)分頁功能的文章就介紹到這了,更多相關(guān)Mybatis Limit分頁內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Access數(shù)據(jù)庫安全的幾個問題2. Windwos下MySQL 64位壓縮包的安裝方法學習記錄3. mysql-bin.000001文件的來源及處理方法4. MySQL中InnoDB和MyISAM類型的差別5. 如何實現(xiàn)MySQL數(shù)據(jù)庫的備份與恢復6. mysql啟動時報錯 ERROR! Manager of pid-file quit without7. MYSQL數(shù)據(jù)庫存文本轉(zhuǎn)存數(shù)據(jù)庫問題8. ACCESS轉(zhuǎn)SQL數(shù)據(jù)庫相關(guān)的幾個技能9. 數(shù)據(jù)庫相關(guān)的幾個技能:ACCESS轉(zhuǎn)SQL10. MySQL中 concat函數(shù)的使用

網(wǎng)公網(wǎng)安備