java与vue实现分页

实现分页功能(笔记)

1.1、后端实现层,通过前端传入PageNum(第几页)以及PageSize(每页的大小),计算出偏移量(Len)

public List<Staffs> qryStaffs(Staffs staffs) {
        staffs.setLen((staffs.getPageNum()-1)*staffs.getPageSize());
        return staffMapper.qryStaffs(staffs);
    }

1.2、 xml通过sql语法查询数据

select * from table1 limit 偏移量,每页大小
<select id="qryStaffs" parameterType="Staffs" resultType="Staffs" resultMap="StaffsMap">
        select * from  demo_test_staff where isdelete != '1'
        <if test="staffName != null and staffName != ''">
            and name like "%"#{staffName,jdbcType=VARCHAR}"%"
        </if>
        <if test="staffGender != null and staffGender != ''">
            and gender = #{staffGender}
        </if>
        <if test="beginTime != null">
            and join_day > #{beginTime}
        </if>
        <if test="endTime != null">
            and #{endTime} > join_day
        </if>
        limit #{len},#{pageSize}
    </select>

2.1前端组件

使用的是element-ui组件中的分页
模块如下:

      <el-pagination background
                     @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     :current-page.sync="currentPage"
                     :page-sizes='[5, 10, 20, 50]'
                     :page-size="qryCondition.pageSize"
                     layout="total, sizes ,prev, pager, next, jumper"
                     prev-text="上一页" next-text="下一页"
                     :total="staffs.total">
      </el-pagination>

方法如下:

// 分页组件
    handleCurrentChange (pageNum) {
      this.qryCondition.pageNum = pageNum
      this.handleQuery()
    },
    handleSizeChange (pageSize) {
      this.qryCondition.pageSize = pageSize
      this.handleQuery()
    },
    handleQuery () {
      this.loading = true
      this.qryStaffs()
    }

不理解的欢迎提问交流,本人菜鸟可以改进博客

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值