Page

package com.xxx.xxx.util;


import java.io.Serializable;
import java.util.List;


public class Page<T> implements Serializable {

    private static final long serialVersionUID = -3640039664184539350L;
        //当前页
        private long page;
        //前一页
        private long prePage;
        //后一页
        private long nextPage;
        //每页大小
        private long pageSize;
        //总条数
        private long totalCount;
        //总页数
        private long pageCount;

        //mysql分页上的SELECT * FROM tableName WHERE crossId = ? LIMIT ?,? ; 第一个limt后第一个问号,在这里计算好,sql那里直接用就好。
        private long sqlFriParm;
        //方便oracle分页sql语法增加的一个属性,oracle 的分页查询:SELECT * FROM ( SELECT A.*,ROWNUM RN FROM (SELECT * FROM  ${tableName} ) A  WHERE ROWNUM <= #{page.sqlEndParm})  TL WHERE RN >= #{page.sqlFriParm}:
        private long sqlEndParm;

        private long beginPageIndex;//页面列表开始索引(包含)

        private long endPageIndex;//页面列表结束索引(包含)

        //当前页数据
        private List<T> rows;


        /**
         * @return the page
         */
        public long getPage() {

            return page;
        }
        /**
         * @param page the page to set
         */
        public void setPage(long page) {
            this.page = page;
        }
        /**
         * @return the prePage
         */
        public long getPrePage() { 
            return prePage;
        }
        /**
         * @param prePage the prePage to set
         */
        public void setPrePage(long prePage) {
            this.prePage = prePage;
        }
        /**
         * @return the nextPage
         */
        public long getNextPage() {
            if(nextPage<=0){
                return 1;
            }else{
                return nextPage>pageCount?pageCount:nextPage;
            }
        }
        /**
         * @param nextPage the nextPage to set
         */
        public void setNextPage(long nextPage) {
            this.nextPage = nextPage;
        }
        /**
         * @return the pageSize
         */
        public long getPageSize() {
            return pageSize;
        }
        /**
         * @param pageSize the pageSize to set
         */
        public void setPageSize(long pageSize) {
            this.pageSize = pageSize<=0?10:pageSize;
        }
        /**
         * @return the totalCount
         */
        public long getTotalCount() {
            return totalCount;
        }
        /**
         * @param totalCount the totalCount to set
         */
        public void setTotalCount(long totalCount) {
            this.totalCount = totalCount;
        }
        /**
         * @return the pageCount
         */
        public long getPageCount() {
            return pageCount;
        }
        /**
         * @param pageCount the pageCount to set
         */
        public void setPageCount(long pageCount) {
            this.pageCount = pageCount;
        }
        /**
         * @return the rows
         */
        public List<T> getRows() {
            return rows;
        }
        /**
         * @param rows the rows to set
         */
        public void setRows(List<T> rows) {
            this.rows = rows;
        }

        public void resetNextPage(){
            nextPage=page+1;
            this.prePage = page -1>0?page-1:1;
            pageCount=totalCount%pageSize==0?totalCount/pageSize:totalCount/pageSize+1;
            //计算beginPageIndex 和 endPageIndex
            if(pageCount <= 10){
                beginPageIndex = 1;
                endPageIndex = pageCount;
            }else {
                beginPageIndex = page -4;
                endPageIndex = page + 5;

                if (beginPageIndex < 1){
                    beginPageIndex = 1;
                    endPageIndex = 10;
                }
                if (endPageIndex > pageCount){
                    endPageIndex = pageCount;
                    beginPageIndex = pageCount - 10 + 1;
                }
            }

        }


        public Page() {
        }

        public Page(long page,long pageSize ){
            this.pageSize = pageSize;
            this.page = page;
            this.sqlFriParm = (page - 1) * pageSize + 1;
            this.sqlEndParm = sqlFriParm + pageSize - 1;
        }

        public long getSqlEndParm() {
            return sqlEndParm;
        }
        public void setSqlEndParm(long sqlEndParm) {
            this.sqlEndParm = sqlEndParm;
        }
        public long getSqlFriParm() {
            return sqlFriParm;
        }

        public void setSqlFriParm(long sqlFriParm) {
            this.sqlFriParm = sqlFriParm;
        }

        public long getBeginPageIndex() {
            return beginPageIndex;
        }

        public void setBeginPageIndex(long beginPageIndex) {
            this.beginPageIndex = beginPageIndex;
        }

        public long getEndPageIndex() {
            return endPageIndex;
        }

        public void setEndPageIndex(long endPageIndex) {
            this.endPageIndex = endPageIndex;
        }

    @Override
    public String toString() {
        return "Page{" +
                "page=" + page +
                ", prePage=" + prePage +
                ", nextPage=" + nextPage +
                ", pageSize=" + pageSize +
                ", totalCount=" + totalCount +
                ", pageCount=" + pageCount +
                ", sqlFriParm=" + sqlFriParm +
                ", beginPageIndex=" + beginPageIndex +
                ", endPageIndex=" + endPageIndex +
                ", rows=" + rows +
                '}';
    }
}
    @ApiOperation(value = "#2--whatever",notes = "")
    @PostMapping("/querydata")
    public Result QueryDimensionTabData(@RequestParam String tableName,@RequestParam Integer currentPage, @RequestParam Integer pageSize){
        logger.info("start ShowDataController.QueryDimensionTabData()...tableName = {},currentPage = {}, pageSize = {}",tableName,currentPage,pageSize);
        long start = System.currentTimeMillis();
        try {
            Page<Map<String, Object>> page = new Page<Map<String, Object>>(currentPage,pageSize);
            page = showDataService.QueryDimensionData(page,tableName);
            page.resetNextPage();
            logger.info("end ShowDataController.QueryDimensionTabData()...cost = {}ms",System.currentTimeMillis() - start);
            return ResultGenerator.genSuccessResult(page);
        } catch (Exception e) {
            logger.error("ShowDataController.QueryDimensionTabData()... Exception = {}",e);
            e.printStackTrace();
            return ResultGenerator.genServerErrorFailResult();
        }

    }
@Override
    public Page<Map<String, Object>> QueryDimensionData(Page<Map<String, Object>> page, String tableName) {
        long totalCount = queryODataMapper.queryTotalCount(tableName.toUpperCase());
        page.setTotalCount(totalCount);
        List<Map<String, Object>> list = queryODataMapper.QueryDimensionData(page,tableName);
        page.setRows(list);
        return page;
    }
package com.xxx.xxx.oracleMapper;

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

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.xxx.xxx.util.Page;

@Mapper
public interface QueryDataMapper {

    @Select("SELECT * FROM ( SELECT A.*,ROWNUM RN FROM (SELECT * FROM  ${tableName} ) A  WHERE ROWNUM <= #{page.sqlEndParm})  TL WHERE RN >= #{page.sqlFriParm}")
    List<Map<String, Object>> QueryDimensionData(
            @Param("page")Page<Map<String, Object>> page,@Param("tableName") String tableName);

    @Select("select count(1) from ${tableName}")
    long queryTotalCount(@Param("tableName")String tableName);

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值