java oracle mysql 分页 工具类 用法

package springboot_001.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Page {

    private int pageSize = 50;
    private int pageIndex = 1;
    private int totalPage;
    private int totalNumber;

    private List<Map<String, Object>> list;
    private Object data;

    public int getStart() {
        int start = (pageIndex - 1) * pageSize;
        if (start < 0) {
            start = 0;
        }
        return start;
    }

    public int getEnd() {
        int end = this.getStart() + pageSize;
        if (end > totalNumber) {
            end = totalNumber;
        }

        return end;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
        if (this.pageIndex < 0) {
            this.pageIndex = 1;
        }
        if (this.pageIndex > totalPage) {
            this.pageIndex = totalPage;
        }
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getTotalNumber() {
        return totalNumber;
    }

    public void setTotalNumber(int totalNumber) {
        this.totalPage = totalNumber % this.pageSize == 0 ?
                totalNumber / this.pageSize : totalNumber / this.pageSize + 1;
        this.totalNumber = totalNumber;
    }

    public List<Map<String, Object>> getList() {
        if (list == null) {
            list = new ArrayList<>();
        }
        return list;
    }

    public void setList(List<Map<String, Object>> list) {
        this.list = list;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
   */
    @Override
    public Result<Object> listApplyListByme(Map<String, Object> params, HttpServletRequest request) {
        Map<String, Object> resMap = new HashMap<>();
        Page page = new Page();
        try {
            // 计算当前页面
            User user = (User) request.getSession().getAttribute("userInfo");
            int pageNumer = Integer.parseInt((String) params.get("pageNumber"));
            int pageSize = Integer.parseInt((String) params.get("pageSize"));
            params.put("founder", user.getUserAgentId());
            int total = flowMapper.getCountPage(params);
            page.setPageSize(pageSize);
            page.setTotalNumber(total);
            page.setPageIndex(pageNumer);
            // 总记录数
            int startRow = page.getStart();
            int endRow = page.getEnd();
            params.put("startRow", startRow);
            params.put("endStartRow", endRow);
            List<Map<String, Object>> appList = flowMapper.listApplyListByme(params);
            page.setList(appList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return Result.buildResult(Result.Status.BAD_REQUEST);
        }
        return Result.buildResult(Result.Status.OK, page);
    }

 

          
          
          select * from (
          select ft.*, rownum as ron
            from (select ot.*
                    from (select count(*) as honor_count, t.user_agentid, t.user_name
                            from t_ows_honor_cup t
                           where 1 = 1
                        
                           group by t.user_agentid, t.user_name) ot
                  
                   order by ot.honor_count desc) ft
                   ) tt
                   
           where tt.ron > 0
             and tt.ron <= 10

注意 oracle一定在分组之后分页

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值