首页 > 编程语言 > 详细

Springboot- pagehelper使用

时间:2019-01-10 23:57:12      阅读:295      评论:0      收藏:0      [点我收藏+]

1.添加pagehelper依赖

<dependency>
            <groupId>org.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.3.2</version>
</dependency>

2.在yml配置

# 分页查询
pagehelper:
    helper-dialect: mysql
    # 查询合理化,如果查询页码小于1,则按第一页查询,查询页码大于最后一页,则查询最后一页
    
    reasonable: true

3.controller

/**
* page 你要查询第几页
* 每页多少行
*/
public Page<Map> findContexts(Integer page, Interger rows){
    
    // 启用分页
// PageHelper中会自动帮我们生成limit 分布语句
// 以及自动帮我们执行查询总数的CountSQL
PageHelper.startPage(page, rows); Page<Map> list = (Page)contentMapper.findAll(); return list; }
@RequestMapping("/list")
@ResponseBody
public Map list(Integer page, Integer limit){
    Page<Map> p = userService.findContents(page, limit);
    // layui对前台返回的数据是有格式要求的
    Map result = new HashMap();
    result.put("code",0);
   result.put("count",page.size) result.put(
"data",page); return result; }

 

Springboot- pagehelper使用

原文:https://www.cnblogs.com/RzCong/p/10252911.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!