自定义数据分页标签

pageModel类存放分页信息

package com.bookstore.Beans;

/**
 * company: www.abc.com
 * Author: ASUS
 * Create Data: 2019/3/11
 */
public class PageModel {
    /**
     * 分页总数据条数
     */
    private int recordCount;
    /**
     * 当前页面
     */
    private int pageIndex;
    /**
     * 每页分多少条数据
     */
    private int pageSize = 4;

    /**
     * 总页数
     */
    private int totalSize;

    public int getRecordCount() {
        this.recordCount = this.recordCount <= 0 ? 0 : this.recordCount;
        return recordCount;
    }

    public void setRecordCount(int recordCount) {
        this.recordCount = recordCount;
    }

    public int getPageIndex() {
        this.pageIndex = this.pageIndex;// <= 0?1:this.pageIndex;
        /** 判断当前页面是否超过了总页数:如果超过了默认给最后一页作为当前页  */
        //this.pageIndex = this.pageIndex>=this.getTotalSize()?this.getTotalSize():this.pageIndex;

        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        //this.pageSize = pageSize;
        return pageSize;
    }

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

    public int getTotalSize() {
        if (this.getRecordCount() <= 0) {
            totalSize = 0;
        } else {
            totalSize = (this.getRecordCount() - 1) / this.getPageSize() + 1;
        }
        return totalSize;
    }


    public int getFirstLimitParam() {
        return (this.getPageIndex() - 1) * this.getPageSize();
    }

}

page.tld文件

<?xml version="1.0" encoding="utf-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                        http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
        version="2.1">

    <!-- 描述 自定义标签版本的一种描述 -->
    <description>Pager 1.0 core library</description>
    <!-- 显示的名称 导包进行的一个展示 -->
    <display-name>Pager core</display-name>
    <!-- 版本号 -->
    <tlib-version>1.0</tlib-version>
    <!-- 短名 -->
    <short-name>fkjava</short-name>
    <!-- uri :导包 -->
    <uri>http://ln.pager-tags</uri>

    <!-- 定义一个标签 -->
    <tag>
        <!-- 标签名 -->
        <name>pager</name>
        <!-- 标签处理类 -->
        <tag-class>com.bookstore.utils.PageTag</tag-class>
        <!-- 设置标签为空 -->
        <body-content>empty</body-content>

        <!-- 定义标签的属性 -->
        <attribute>
            <!-- 属性名 表示分页的第几页 -->
            <name>pageIndex</name>
            <!-- 必须的 -->
            <required>true</required>
            <!-- run time expression value 为true支持EL表达式 -->
            <rtexprvalue>true</rtexprvalue>
        </attribute>

        <!-- 定义标签的属性 -->
        <attribute>
            <!-- 属性名 表示分页标签 ,每页显示多少条数据 -->
            <name>pageSize</name>
            <!-- 必须的 -->
            <required>true</required>
            <!-- run time expression value 为true支持EL表达式 -->
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <!-- 定义标签的属性 -->
        <attribute>
            <!-- 属性名  记录分页的总数 -->
            <name>recordCount</name>
            <!-- 必须的 -->
            <required>true</required>
            <!-- run time expression value 为true支持EL表达式 -->
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <!-- 定义标签的属性 -->
        <attribute>
            <!-- 属性名 -->
            <name>submitUrl</name>
            <!-- 必须的 -->
            <required>true</required>
            <!-- run time expression value 为true支持EL表达式 -->
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <!-- 定义标签的属性 -->
        <attribute>
            <!-- 属性名 -->
            <name>style</name>
            <!-- 必须的 -->
            <required>false</required>
            <!-- run time expression value 为true支持EL表达式 -->
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
</taglib>

前台页面中的显示信息

<%@ taglib prefix="ln" uri="http://ln.pager-tags" %>
<tr>
                                    <td>
                                    <ln:pager
                                        pageIndex="${pageModel.pageIndex}"
                                        pageSize="${pageModel.pageSize}"
                                        recordCount="${pageModel.recordCount}"
                                        submitUrl="${pageContext.request.contextPath}/client/findOrderByUser.do?pageIndex={0}"/>

                                    </td>

                                </tr>
原文地址:https://www.cnblogs.com/liuna369-4369/p/10931055.html