首页 > 其他分享 >pagehelper

pagehelper

时间:2024-09-12 22:47:37浏览次数:1  
标签:pageSize clazzList clazz pageBean pagehelper LocalDate page

1.分页插件依赖

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

入参
@GetMapping
public Result showClazzPage(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
@RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
String name, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
PageBean pageBean = clazzService.showClazzPage(page, pageSize, name, begin, end);
return Result.success(pageBean);
}
使用
public PageBean showClazzPage(Integer page, Integer pageSize, String name, LocalDate begin, LocalDate end) {
PageBean pageBean = new PageBean();
//开启分页
PageHelper.startPage(page, pageSize);
Page clazzList = clazzMapper.selectClazzPage(name, begin, end);
//计算状态
for (Clazz clazz : clazzList) {
LocalDate beginDate = clazz.getBeginDate();//开课时间
LocalDate endDate = clazz.getEndDate();//结课时间
LocalDate localDate = LocalDate.now();//当前时间
if (!beginDate.isBefore(localDate)) {
clazz.setStatus("未开班");
continue;
} else if (localDate.isBefore(endDate)) {
clazz.setStatus("在读");
continue;
}else {
if (endDate.isBefore(localDate)) {
clazz.setStatus("已结课");
}else {
clazz.setStatus("未知");
}
}

    }
    pageBean.setTotal(clazzList.getTotal());//班级总数量
    pageBean.setRows(clazzList);//页面信息
    return pageBean;
}

标签:pageSize,clazzList,clazz,pageBean,pagehelper,LocalDate,page
From: https://www.cnblogs.com/gracious/p/18411272

相关文章

  • pageHelper分页插件导致的查询慢的问题优化
    首先在yml中配置mybatis:configuration:log-impl:org.apache.ibatis.logging.stdout.StdOutImpl会进行sql语句打印问题:进行分页查询时pageHelper自动生成的count语句相当于在查询语句外包一层selectcount(1)from(你的查询语句)对于你的查询语句的返回条件中有较......
  • 使用Mybatis 的PageHelper插件实现分页查询功能
    Mybatis提供了一个分页插件PageHelper,它会帮助我们自动完成分页和获取总数量的操作,可以方便实现分页查询。第一步,在pom.xml文件引入PageHelper依赖。<dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-s......
  • Mybatis里PageHelper的分页
    com.github.pagehelper.Page#Page(int,int,boolean,java.lang.Boolean)130pageNum==1&&pageSize==Integer.MAX_VALUE设置则不分页,设置pageSize=0并且pageSizeZero=true继续看拦截器请求注意如果是平时,pageSize<=0是不会去分页,pageSize=0回去count,com.github.pa......
  • 分页插件pagehelper使用方法
    使用方法1.引入分页插件 1).使用Maven在pom.xml中添加如下依赖:<dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>最新版本</version></dependency> 2).使用Gr......
  • springboot~mybatis-pagehelper原理与使用
    原理PageHelper是一个用于MyBatis的分页插件,pagehelper-spring-boot-starter是其在SpringBoot中的集成组件。下面简要介绍PageHelper的分页原理:PageHelper的分页原理拦截器机制:PageHelper通过MyBatis的拦截器机制实现分页功能。它会在SQL执行前拦截并修改SQL语句,添加分页相......
  • 使用PageHelper在同一个返回值接口中返回数据条数不对
    写这篇的原因:在同一个返回值的接口中调用两次分页,前端调接口发现一次的分页总数total是正常的,另一个是分页设置的一页的数量,别的不显示。pom中用到的依赖<dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</arti......
  • 自定义PageHelper分页工具
    今天写了一个需要用到分页查询的需求大概是这样的有一张项目表和一张报警表如下:项目表:报警表:现在我就是要根据这个项目名称,报警类型和报警时间来查询报警列表.项目可以模糊查询,看似是很简单的一个需求,但是我遇到了一个问题我的大概思路就是先用项目名称去项目表......
  • Mybatis PageHelper编译SQL引发的一次性能问题.18286262
    起源最近一直在跟大佬们做公司项目的性能优化,我这种小卡乐咪基本上负责的就是慢接口优化,但实际上只有以下几种情况需要进行接口代码级别的改造:循环查库、RPC数据库设计不合理业务流程太长,代码耦合性太高等随着对接口分析的深入,我们越来越发现系统中有很多拖后腿的问题是与......
  • pageHelper在Spring框架中pageSize无法修改的问题
    以前在Springboot中分页是使用pageHelper的,然后想当然的以为在老项目Spring框架上也可以完美复制粘贴进去,结果运行起来pageHelper的pageSize一直是全部列表的长度,即(total始终等于pagesize,page始终等于1)这就相当于没分页。后来发现,pageHelper在Spring中的写法和Springboot的是......
  • 若依RuoYi-Vue分离版—PageHelper分页的坑
    若依RuoYi-Vue分离版—PageHelper分页的坑(一)读取分页属性(pageNum、pageSize)只支持Parameter对象(二)PageHelper分页本身的使用方式的坑(一)读取分页属性(pageNum、pageSize)只支持Parameter对象若依中的PageHelper的分页读取只支持get请求的Parameter对象例如:http://local......