springboot+mybatis+vue2分页功能开发

前端框架代码

复制代码
 <div class="block">
    <span class="demonstration">完整功能</span>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[100, 200, 300, 400]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400">
    </el-pagination>
  </div>

data中进行数据初始化

javascript 复制代码
data() {
    return {    
      totals: 0,
      pageSize: 2,
      currentPage: 1
}
}

对应的js代码

javascript 复制代码
 methods: {
    getParent() {
      getPatientList(this.currentPage, this.pageSize).then(res => {
        this.tableData = res.data.list
        this.totals = res.data.total
      })
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.getParent()
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.getParent()
      console.log(`当前页: ${val}`)
    }
}

后端开发方法

这里使用的是mybatis,所有需要使用pagehelper进行分页

javascript 复制代码
 <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.4.7</version>
        </dependency>

后端使用

复制代码
PageInfo,并将pageNO和pageSize作为参数传入后端,就可以完成分页了
相关推荐
Mcband6 分钟前
forEach跳出循环
java
期待のcode8 分钟前
Springboot多数据源配置
java·数据库·spring boot·后端·mybatis
Knight_AL13 分钟前
深入解析 Spring 循环依赖:如何通过三级缓存解决 A ↔ B 的依赖问题
java·spring·缓存
自在极意功。26 分钟前
深入解析JDBC:Java数据库操作的基础
java·开发语言·数据库·jdbc
程序员鱼皮27 分钟前
什么是负载均衡?不就是加台服务器嘛!
java·后端·计算机·程序员·编程经验
加洛斯34 分钟前
Spring Task从入门到精通:定时任务开发完整教程
java·后端
月明长歌37 分钟前
【码道初阶】Leetcode155踩坑最小栈问题:最小栈:算法对了,却输给了 Java 的 “==“?
java·算法·
小飞Coding39 分钟前
你写的 equals() 和 hashCode(),正在悄悄吃掉你的数据!
java·后端