• pagehelper的使用


    pagehelper的使用

    后端

    依赖

    <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper-spring-boot-starter</artifactId>
        <version>1.2.13</version>
    </dependency>
    

    配置

    pagehelper:
      helperDialect: mysql
      reasonable: true
      supportMethodsArguments: true
      pageSizeZero: false
    

    控制层

    @GetMapping("/reports/{page}/{size}")
    public PageInfo queryReportList(@PathVariable("page") int page, @PathVariable("size") int size) {
        PageHelper.startPage(page, size);
        PageInfo info = new PageInfo<>(reportService.queryReportList());
        return info;
    }
    

    前端

    分页@current-change="page"

    currentPage改变时会触发

    <el-pagination
      background
      layout="prev, pager, next"
      :page-size="pageSize"
      :total="total"
      @current-change="page">
    </el-pagination>
    

    通过axios接收后端的数据this.$axios.get().then()

    <script>
      export default {
        methods: {
          page (currentPage) {
            const _this = this
            this.$axios.get('http://localhost:8081/reports/' + currentPage + '/2').then(function (resp) {
              _this.tableData = resp.data.list
            })
          }
        },
    
        data () {
          return {
            tableData: [],
            pageSize: 0,//初始值,避免报错
            total: 0//初始值,避免报错
          }
        },
        created () {
          const _this = this
          this.$axios.get('http://localhost:8081/reports/1/2').then(function (resp) {
            _this.tableData = resp.data.list
            _this.pageSize = resp.data.pageSize
            _this.total = resp.data.total
          })
        }
      }
    </script>
    
  • 相关阅读:
    http请求
    mac chrome NET::ERR_CERT_INVALID
    百度小程序获取用户手机号
    js 异步总结
    百度小程序 es6 支持情况
    每日日报
    每日日报
    每日日报
    05程序员修炼之道:从小工到专家阅读笔记之二
    05程序员修炼之道:从小工到专家阅读笔记之一
  • 原文地址:https://www.cnblogs.com/pinked/p/12432162.html
Copyright © 2020-2023  润新知