mybatis 整合pageHelper
1.引入依賴,注意引入springboot整合的依賴
如果不引入的不是springboot整合的依賴,需maven 引入插件
<!-- 分頁(yè)插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
2 配置application.proterties
pagehelper.helper-dialect=mysql
pagehelper.reasonable=true
pagehelper.support-methods-arguments=true
pagehelper.params=count=countSql
3. 寫sql語(yǔ)句
<select id="findAll" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_user
</select>
4 service實(shí)現(xiàn)分頁(yè)
public PageInfo<User> findAll(int currentPage, int pageSize) {
PageHelper.startPage(currentPage,pageSize);
List<User> list = userMapper.findAll();
return new PageInfo<User>(list);
}
5.controller調(diào)用
@RequestMapping("page")
public PageInfo<User> page(int currentPage, int pageSize){
return userService.findAll(currentPage, pageSize);
}
6.調(diào)用結(jié)果顯示
// 20190622090951
// http://127.0.0.1:8082/page?currentPage=3&pageSize=3
{
"pageNum": 3,
"pageSize": 3,
"size": 3,
"startRow": 7,
"endRow": 9,
"total": 10,
"pages": 4,
"list": [
{
"id": 9,
"username": "bajie",
"password": "123456",
"createTime": "2019-06-21T16:00:00.000+0000",
"trueName": "豬八戒",
"remarks": null,
"bz": null
},
{
"id": 10,
"username": "wukong",
"password": "123456",
"createTime": "2019-06-21T16:00:00.000+0000",
"trueName": "孫悟空",
"remarks": null,
"bz": null
},
{
"id": 11,
"username": "shasheng",
"password": "123456",
"createTime": "2019-06-21T16:00:00.000+0000",
"trueName": "沙悟凈",
"remarks": null,
"bz": null
}
],
"prePage": 2,
"nextPage": 4,
"isFirstPage": false,
"isLastPage": false,
"hasPreviousPage": true,
"hasNextPage": true,
"navigatePages": 8,
"navigatepageNums": [
1,
2,
3,
4
],
"navigateFirstPage": 1,
"navigateLastPage": 4,
"firstPage": 1,
"lastPage": 4
}