欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

Spring Boot 中PageHelper 插件使用配置思路详解

时间:2022-05-06 09:21:26|栏目:JAVA代码|点击:

使用思路

1.引入myabtis和pagehelper依赖

2.yml中配置mybatis扫描和实体类

这2行代码
pageNum:当前第几页
pageSize:显示多少条数据
userList:数据库查询的数据数据列表

PageHelper.startPage(pageNum, pageSize);
PageInfo pageInfo = new PageInfo(userList);
最后返回一个pageInfo 对象即可,pageInfo 这个对象中只有数据一些信息,但是,没有成功失败的状态或者提示语。
真实企业中会封装一个返回对象,把pageInfo 放到对象中

1.pom依赖

方法一:使用原生的PageHelper

1.在pom.xml中引入依赖,刷新自动加载jar

 <dependency>

        <groupId>com.github.pagehelper</groupId>

        <artifactId>pagehelper</artifactId>

        <version>5.2.1</version>

    </dependency>

方法二 本人使用 PageHelper的starter

1.导入pom.xml依赖

  <dependency>

        <groupId>com.github.pagehelper</groupId>

        <artifactId>pagehelper-spring-boot-starter</artifactId>

        <version>1.2.12</version>

    </dependency>

2.在application.properties或者application.yml格式配置pagehelper的属性

二选一

#pagehelper分页插件配置application.properties

    pagehelper.helper-dialect=mysql

        pagehelper.reasonable=true

        pagehelper.support-methods-arguments=true

        pagehelper.params=count=countSql

application.yml

 hepagehelper:

          lperDialect: mysql

          reasonable: true

          supportMethodsArguments: true

          params: count=countSql

Controller层调用 测试

@RequestMapping("findallCar")

public String findallCar(Model model, HttpSession session) {

    PageHelper.startPage(1,5);

    List<CarTable> carTables = service.findallCar();

    PageInfo<CarTable> page = new PageInfo<CarTable>(carTables);

    System.out.println(page);

    model.addAttribute("carall", carTables);

    session.setAttribute("caralls", carTables);

    return "carinsert";
}
  PageHelper.startPage(1,5);

     List<CarTable> carTables = service.findallCar();

    PageInfo<CarTable> page = new PageInfo<CarTable>(carTables);

    System.out.println(page);

上一篇:SpringBoot打印POST请求原始入参body体方式

栏    目:JAVA代码

下一篇:springboot如何接收application/x-www-form-urlencoded类型的请求

本文标题:Spring Boot 中PageHelper 插件使用配置思路详解

本文地址:http://www.codeinn.net/misctech/201159.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有