目录
前言:
控制台层:
分页工具类:
mybatis 手写分页 :
控制层
这个是XML sql:
控制台统计封装的返回格式:
目录
前言:
控制台层:
分页工具类:
前言:
我只是记录一下笔记,没有太多时间 细写,
搬砖太忙! 有疑问可以留言 ,知无不言
谢谢
我只是记录一下笔记,没有太多时间 细写,
搬砖太忙! 有疑问可以留言 ,知无不言
谢谢
控制台层:
CX平台
起始页和页数 就在控制台传就行了, 实现层不需要
PageBeanUtils.initPageBean(cardDetail, current, rowCount);
{
//整合参数
HashMap searchParams = new HashMap<>();
if (StringUtils.isNotBlank(merchantNo)) {
searchParams.put("merchantNo", merchantNo);
}
if (StringUtils.isNotBlank(startDate)) {
searchParams.put("startDate", startDate);
}
if (StringUtils.isNotBlank(endDate)) {
searchParams.put("endDate", endDate);
}
List cardDetail = sumSellCardService.getMonthBySellCardDetail(searchParams);
if (cardDetail.size()>0){
// PageBean
这个分页用于的sql:
分页工具类:
package cn.bsit.shared.utils;
import cn.bsit.commons.page.PageBean;
import cn.bsit.commons.page.PageUtils;
import java.util.List;
import java.util.stream.Collectors;
public class PageBeanUtils {
public static PageBean initPageBean(List list, Integer current, Integer rowCount){
// 处理sumList集合
PageBean p = new PageBean<>();
long count = list.size();
current = PageUtils.initPageCount(rowCount, current, count);
rowCount = PageUtils.initRowCount(rowCount);
p.setCurrent(current);
p.setRowCount(rowCount);
p.setTotal(count);
if(count == 0){ //空数据
p.setRows(null);
} else {
//存在信息列表,分页当前集合
list = list.stream().skip((current - 1) * rowCount).limit(rowCount).collect(Collectors.toList());
//封装分页参数
p.setRows(list);
}
return p;
}
}
package cn.bsit.shared.utils;
import cn.bsit.commons.page.PageBean;
import cn.bsit.commons.page.PageUtils;
import java.util.List;
import java.util.stream.Collectors;
public class PageBeanUtils {
public static PageBean initPageBean(List list, Integer current, Integer rowCount){
// 处理sumList集合
PageBean p = new PageBean<>();
long count = list.size();
current = PageUtils.initPageCount(rowCount, current, count);
rowCount = PageUtils.initRowCount(rowCount);
p.setCurrent(current);
p.setRowCount(rowCount);
p.setTotal(count);
if(count == 0){ //空数据
p.setRows(null);
} else {
//存在信息列表,分页当前集合
list = list.stream().skip((current - 1) * rowCount).limit(rowCount).collect(Collectors.toList());
//封装分页参数
p.setRows(list);
}
return p;
}
}
============
mybatis 手写分页 :
可以手写分页,适用于sql语句为 select * from where xxx ,后面就不需要跟其他函数了
count条数的话 就是: select count(*) from where xxx ,后面就不需要跟其他函数了
如果where 后面有使用 分组等统计查询,例如按照月份统计数据, 这样就不能使用这种方法
控制层
Service层:
impl层:
这个是XML sql:
这个count统计的条数 必须跟返回数据的 查询条件一致!!
如果where 后面有使用 分组等统计查询,例如按照月份统计数据, 这样就不能使用这种方法
order by pl.id DESC limit #{page},15 and pl.classfiy_name like CONCAt('%',#{condition},'%') and pl.label_name like CONCAt('%',#{label},'%')


![[Jpa框架 实现分页] JPA/Mybatis 二个持久化框架之分页总结..待更新 [Jpa框架 实现分页] JPA/Mybatis 二个持久化框架之分页总结..待更新](http://www.mshxw.com/aiimages/31/592024.png)
