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
//计算状态
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