zoukankan      html  css  js  c++  java
  • Springboot- pagehelper使用

    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; }
  • 相关阅读:
    FTP Protocol
    File Operations
    Ubuntu Install Chinese Input Method
    Vim Intro
    ISA Introduction
    Fourier Transform
    Process/Thread Synchronization
    Process Synchronization-Example 2
    leetcode 栈和队列类型题
    leetcode 字符串类型题
  • 原文地址:https://www.cnblogs.com/RzCong/p/10252911.html
Copyright © 2011-2022 走看看