提高开发效率-分页查询


-------------------------controller---------------------------------------------------------
@RequestMapping(value = "/giftList", method = RequestMethod.GET)
public Protocol<ProtocolPager<GiftRaffleOut>> giftList(String _appId, GiftRaffleIn giftRaffleIn) {
    ParamsValid valid = new ParamsValid();
    valid.validAppId(_appId);
    if (!valid.isValid()) {
        return valid.showInValidMessage();
    }
    try {
        return giftRaffleRecordService.giftList(giftRaffleIn);
    } catch (Exception ex) {
        logger.error("GiftRaffleRecordController.giftList获取奖品列表出错", ex);
        return new Protocol(1, "获取奖品列表出错");
    }
}

 -----------------------列表分页service-------------------------------------------------------
logger.warn("SubjectService.getAllSubjectType入参: " + JSON.toJSONString(subjectTypeIn));
int count = subjectTypeMapper.getAllSubjectTypeCount(subjectTypeIn);
if (count < 1) {
    logger.warn("SubjectService.getAllSubjectType专题列表分页查询无结果");
    return new Protocol(new ProtocolPager(), 0, "查询无结果");
}
List<SubjectType> subjectTypeList = subjectTypeMapper.getAllSubjectType(subjectTypeIn);
ProtocolPager protocolPager = new ProtocolPager(
        subjectTypeList,subjectTypeIn.getPageSize(),subjectTypeIn.getPageIndex(),count);
return new Protocol<>(protocolPager, 0, "");
-----------------------分页mapper.xml----------------------------------------------------------------------------------------------------
<select id="getAllSubjectType" resultMap="BaseResultMap" parameterType="com.autohome.dealer.vrar.contract.in.chezhan.SubjectTypeIn">
    ;WITH temp as(
        select
        <include refid="Base_Column_List"/> ,
        ROW_NUMBER () OVER (order by CreateTime DESC) as rowNum
        FROM SubjectType WITH (nolock)
        WHERE 
        <foreach collection="list" item="item" separator=",">
        (#{item.activityId})
        </foreach>
        <if test="subjectTypeName!=null and subjectTypeName!=''">
        and SubjectTypeName like '%'+#{subjectTypeName}+'%'
        </if>
        <if test="category!=null">
            and category = #{category}
        </if>
    )
    select * from temp t
    where t.rowNum between #{rowBegin} and #{rowEnd}
</select>

 

页面js分页实现:如果页数大于6,则大于3页的页数用...来展示,显示前3页后3页,如果不足6页则正常显示

loadStatisTable: function (pageIndex) {
    $.ajax({
        url: '/datastatis/dealerorder/getDealerOrderDataList',
        dataType: 'json',
        type: 'get',
        data: {
            pageIndex: pageIndex,
            pageSize: pageSize,
            reportDateStart: reportDateStart,
            reportDateEnd: reportDateEnd,
            dealerId: dealerId
        },
        success: function (data) {
            if (data == null || data.list == null) {
                $('.ics_table_v1').empty().append(template('defaultStatisTableTemplate', {
                    Data: data
                }));
                zhwx.dealer.loadStatisTableNum(1, 1, 0);
                return;
            }
            if (data) {
                $('.ics_table_v1').empty().append(template('statisTableTemplate', {
                    Data: data
                }));
                zhwx.dealer.loadStatisTableNum(data.pagecount, data.pageindex, data.rowcount);
            }
        },
        error: function (data) {
            $('.ics_table_v1').empty().append(template('defaultStatisTableTemplate', {
                Data: data
            }));
        }
    });
},
loadPreOrNextPage: function (obj, pageCount) {
    var currentPage = $(".ics_page_v1 .current").html();
    if ($(obj).hasClass("page-prev")) {
        if (currentPage != 1) {
            zhwx.dealer.loadStatisTable(parseInt(currentPage) - 1);
        }
    } else {
        if (currentPage != pageCount) {
            zhwx.dealer.loadStatisTable(parseInt(currentPage) + 1);
        }
    }
},
loadJumpPage: function (pageCount) {
    var pageNumber = $("#pageNumber").val();
    if (pageNumber !== '' && pageNumber !== null && pageNumber !== undefined && pageNumber > 0 && pageNumber <= pageCount) {
        zhwx.dealer.loadStatisTable(pageNumber);
    }
},
loadStatisTableNum: function (pageCount, pageIndex, rowcount) {
    var pageNumHtml = "<span class='mr10 font-12'>共 <em>" + rowcount + "</em> 天 </span>";
    pageNumHtml += "<a onclick='homeCompass.zhwx.dealer.loadPreOrNextPage(this," + pageCount + ")' class='page-prev page-disabled ' href='javascript:void(0); '></a>";
    if (pageCount < 6) {
        for (var i = 1; i < pageCount + 1; i++) {
            if (pageIndex == i) {
                pageNumHtml += "<a class='current' onclick='homeCompass.zhwx.dealer.loadStatisTable(" + i + ")' href='javascript:void(0);'>" + i + "</a>";
            } else {
                pageNumHtml += "<a onclick='homeCompass.zhwx.dealer.loadStatisTable(" + i + ")' href='javascript:void(0);'>" + i + "</a>";
            }
        }
    } else if (pageIndex < 3 || pageIndex > pageCount - 2) {
        var hadDraw = false;
        for (var i = 1; i < pageCount + 1; i++) {
            if (i < 3 || i > pageCount - 2) {
                if (pageIndex == i) {
                    if (pageIndex == 2) {
                        pageNumHtml += "<a class='current' onclick='homeCompass.zhwx.dealer.loadStatisTable(" + i + ")' href='javascript:void(0);'>" + i + "</a>";
                        pageNumHtml += "<a onclick='homeCompass.zhwx.dealer.loadStatisTable(" + (i + 1) + ")' href='javascript:void(0);'>" + (i + 1) + "</a>";
                    } else if (pageIndex == pageCount - 1) {
                        pageNumHtml += "<a onclick='homeCompass.zhwx.dealer.loadStatisTable(" + (i - 1) + ")' href='javascript:void(0);'>" + (i - 1) + "</a>";
                        pageNumHtml += "<a onclick='homeCompass.zhwx.dealer.loadStatisTable(" + i + ")' class='current' href='javascript:void(0);'>" + i + "</a>";
                    } else {
                        pageNumHtml += "<a onclick='homeCompass.zhwx.dealer.loadStatisTable(" + i + ")' class='current' href='javascript:void(0);'>" + i + "</a>";
                    }
                } else {
                    pageNumHtml += "<a onclick='homeCompass.zhwx.dealer.loadStatisTable(" + i + ")' href='javascript:void(0);'>" + i + "</a>";
                }
            } else if (!hadDraw) {
                pageNumHtml += "<span class='page-ellipsis'>...</span>";
                hadDraw = true;
            }
        }
    } else {
        var hadDraw = false;
        for (var i = 1; i < pageCount + 1; i++) {
            if (i < 3 || i > pageCount - 2 || (i > pageIndex - 2 && i < pageIndex + 2)) {
                if (pageIndex == i) {
                    pageNumHtml += "<a class='current' onclick='homeCompass.zhwx.dealer.loadStatisTable(" + i + ")' href='javascript:void(0);'>" + i + "</a>";
                } else {
                    pageNumHtml += "<a onclick='homeCompass.zhwx.dealer.loadStatisTable(" + i + ")' href='javascript:void(0);'>" + i + "</a>";
                }
                hadDraw = false;
            } else if (!hadDraw) {
                pageNumHtml += "<span class='page-ellipsis'>...</span>";
                hadDraw = true;
            }
        }
    }
    pageNumHtml += "<a onclick='homeCompass.zhwx.dealer.loadPreOrNextPage(this," + pageCount + ")' class='page-next ' href='javascript:void(0); '></a>";
    pageNumHtml += "<span class='ml15 '>跳转</span>";
    pageNumHtml += "<input type='text ' id='pageNumber' class='ics_input_v1 ml10 mr10 ' style='width:50px;height: 28px;line-height: 28px '>";
    pageNumHtml += "<span>页</span>";
    pageNumHtml += "<a onclick='homeCompass.zhwx.dealer.loadJumpPage(" + pageCount + ")' href='javascript:void(0);' class='current ml10'>GO</a>";
    $(".ics_page_v1").html(pageNumHtml);
    if (pageCount == 1) {
        $(".page-prev").addClass("page-disabled");
        $(".page-next").addClass("page-disabled");
    } else if (pageIndex == 1) {
        $(".page-prev").addClass("page-disabled");
        $(".page-next").removeClass("page-disabled");
    } else if (pageIndex == pageCount) {
        $(".page-next").addClass("page-disabled");
        $(".page-prev").removeClass("page-disabled");
    } else {
        $(".page-prev").removeClass("page-disabled");
        $(".page-next").removeClass("page-disabled");
    }
},

效果图
 

!-- 表格 -->
        <div class="ics_box_v1 mb20 js-filter-box">
            <div class="box-hd">报表
                <a href="javascript:void(0);" οnclick="exportExcel()" class="ics_btn_v1 ics_btn_v1-blue noshadow font-12 fn-right ">导出</a>
            </div>
            <div class="box-bd">
                <table class="ics_table_v1 mb20">
                    <thead>
                    <tr>
                        <th>日期</th>
                        <th>顾问</th>
                    </tr>
                    </thead>
                </table>

                <!-- page -->
                <div class="ics_page_v1 txt-right">
                    <!-- start 总共页码(根据需求添加或删除) -->
                <#--<span class="mr10 font-12">共 <em>40</em> 条 </span>-->
                    <!-- end 总共页码 -->
                    <!-- 前一页 -->
                <#--<a class="page-prev page-disabled " href="# "></a>-->
                    <!-- 数字 -->
                <#--<a class="current " href="# ">1</a> <a href="# ">2</a>-->
                <#--<a href="# ">3</a> <a href="# ">4</a> <a href="# ">5</a>-->
                <#--<!-- 省略号 &ndash;&gt;-->
                <#--<span class="page-ellipsis ">...</span> <a href="# ">999</a>-->
                    <!-- 下一页 -->
                <#--<a class="page-next " href="# "></a>-->

                    <!-- start 输入页面跳转(根据需求添加或删除) -->
                <#--<span class="ml15 ">跳转</span>-->
                <#--<input type="text " class="ics_input_v1 ml10 mr10 " style="width:50px;height: 28px;line-height: 28px ">-->
                <#--<span>页</span>-->
                <#--<a href="javascript:void(0);" class="current ml10">GO</a>-->
                    <!-- end 输入页面跳转 -->
                </div>
            </div>
        </div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值