Mybatis Limit實(shí)現(xiàn)分頁功能
1.1 為什么需要分頁 減少數(shù)據(jù)的處理量
1.2 使用Limit實(shí)現(xiàn)分頁
select * from user limit startIndex,pageSize; # 注意是從startIndex+1開始查詢 pageSize 個(gè)select * from user limit 3; # [0,3]
1.3 使用mybatis實(shí)現(xiàn)分頁(核心:SQL)
1.3.1 接口
UserMapper.java
// limit實(shí)現(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實(shí)現(xiàn)分頁功能的文章就介紹到這了,更多相關(guān)Mybatis Limit分頁內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Windows下不能啟動(dòng)mysql服務(wù)--錯(cuò)誤總結(jié)2. mybatis plus代碼生成工具的實(shí)現(xiàn)代碼3. 數(shù)據(jù)庫相關(guān)的幾個(gè)技能:ACCESS轉(zhuǎn)SQL4. navicat for mysql導(dǎo)出sql文件的方法5. Access數(shù)據(jù)庫安全的幾個(gè)問題6. Navicat Premium操作MySQL數(shù)據(jù)庫(執(zhí)行sql語句)7. 淺談Mysql連接數(shù)據(jù)庫時(shí)host和user的匹配規(guī)則8. SQL Server下7種“數(shù)據(jù)分頁”方案全網(wǎng)最新最全9. navicat for mysql導(dǎo)出數(shù)據(jù)庫的方法10. MYSQL技巧:為現(xiàn)有字段添加自增屬性
