1. Limit實現(xiàn)分頁
1.1 為什么需要分頁
減少數據的處理量
1.2 使用Limit實現(xiàn)分頁
1
2
3
|
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
1
2
|
// limit實現(xiàn)分頁 Map后面只能是 Integer 包裝類 不可以 int List<User> getUserByLimit(Map<String, Integer> map); |
1.3.2 UserMapper.xml
1
2
3
4
5
|
< select id = "getUserByLimit" resultMap = "com.tian.pojo.User" parameterType = "map" > select * from mybatis.user limit #{statrIndex},#{pageSize}; </ select > |
1.3.3 測試類
UserMapperTest.java
1
2
3
4
5
6
7
8
9
10
11
12
|
< select id = "getUserByLimit" resultMap = "UserMap" parameterType = "map" > select * from `mybatis`.`user` limit #{startIndex},#{pageSize}; </ select > < select id = "getUserById" resultMap = "UserMap" > select * from `mybatis`.`user` where id = #{id}; </ select > |
執(zhí)行結果:
到此這篇關于Java之mybatis使用limit實現(xiàn)分頁案例講解的文章就介紹到這了,更多相關Java之mybatis使用limit實現(xiàn)分頁內容請搜索服務器之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/I_r_o_n_M_a_n/article/details/115653343