springboot整合分页复习

闲话不多说直接开始

1.导入依赖

 <!-- 分页-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.12</version>
        </dependency>

2.配置properties,我用的是yml 文件以下是新添加的

#    分页依赖
    hepagehelper:
      lperDialect: mysql
      reasonable: true
      supportMethodsArguments: true
      params: count=countSql

3.后端代码实现:可能会和大家的有出入

 //跳转页面
    @RequestMapping("/refresherCourse")
    public String refresher(HttpSession session ,Model model) {
        model.addAttribute("state",0);
        PageHelper.startPage(1,4);
        StudentTable table= (StudentTable) session.getAttribute("data");
        model.addAttribute("stu",table);
        List<CourseTable> tabless= courseService.findAll();
        PageInfo<CourseTable> pageInfo = new PageInfo<CourseTable>(tabless);
        model.addAttribute("tabless",tabless);
        model.addAttribute("PageInfo",pageInfo);
        return "refresherCourse";
    }


 //以下这个是点击下一页 上一页或者尾页 刷新页面
    @RequestMapping("/PageDown")
    public String PageDown(Model model,CourseTable table ,@RequestParam(defaultValue = "1",value ="pageNum")Integer pageNum,HttpSession session){
        PageHelper.startPage(pageNum,4);
        List<CourseTable> tabless= courseService.findAll();
        PageInfo<CourseTable> pageInfo = new PageInfo<CourseTable>(tabless);
        model.addAttribute("PageInfo",pageInfo);
        return "refresherCourse";
    }
//上述方法也可直接返回json  然后进行解析  局部刷新

4.前端实现


        <table>
          <thead>
          <tr>
            <td 这里是遍历值>
              
            </td>
          </tr>
          </thead>
          <tbody>
          </tbody>
        </table>
        <div align="center">
          <p>当前 <span th:text="${tabless.pageNum}"></span> 页,总 <span th:text="${tabless.pages}"></span> 页,共 <span th:text="${tabless.total}"></span> 条记录</p>
          <a th:href="@{/refresherCourse}">首页</a>
          <a th:href="@{PageDown(pageNum=${PageInfo.hasPreviousPage}?${PageInfo.prePage}:1)}">上一页</a>
          <a th:href="@{PageDown(pageNum=${PageInfo.hasNextPage}?${PageInfo.nextPage}:${PageInfo.pages})}">下一页</a>
          <a th:href="@{PageDown(pageNum=${PageInfo.pages})}">尾页</a>
        </div>

代码命名不是很规范,敬请谅解

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

能像风一样

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值