每日bug pagehelper 分页不生效,总页数总是1解决方案

使用了分页mybatis的分页插件pagehelper,但是在分页的过程中遇到了一个大坑,也就是分页总页数总是1。下面是代码:

public String getAllEmployee(Model model, @RequestParam(value = "pn",defaultValue = "1")Integer pn){

        //下面开始分页的代码
        List<Employee> allEmployee = employeeService.getAllEmployee();
        PageHelper.startPage(pn,5);
        PageInfo pageInfo=new PageInfo(allEmployee,5);
        model.addAttribute("pageInfo",pageInfo);
        return "list";

    }

查看了下面的文章 找到了原因

https://blog.csdn.net/qq_41262903/article/details/88556371

在这里插入图片描述

public String getAllEmployee(Model model, @RequestParam(value = "pn",defaultValue = "1")Integer pn){

        //下面开始分页的代码
        //注意下面的代码=====================================================
         PageHelper.startPage(pn,5);
         
        List<Employee> allEmployee = employeeService.getAllEmployee();
       
        PageInfo pageInfo=new PageInfo(allEmployee,5);
        model.addAttribute("pageInfo",pageInfo);
        return "list";

    }

PageHelper.startPage(pn,5); 需要在查询数据的上面执行;PageHelper.startPage(pn,5);只对该语句以后的第一个查询语句得到的数据进行分页。

而我在PageHelper.startPage(1,10)该语句之前就已经执行了查询语句,所以不起作用。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值