基于PageInfo分页工具的分页工具(笑)

com.utils.FenyeUtil

package com.utils;

import com.github.pagehelper.PageInfo;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;

public class FenyeUtil extends SimpleTagSupport {

    private String url;//请求地址
    private PageInfo pageInfo;//保存分页所需的数据

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public PageInfo getPageInfo() {
        return pageInfo;
    }

    public void setPageInfo(PageInfo pageInfo) {
        this.pageInfo = pageInfo;
    }

    @Override
    public void doTag() throws JspException, IOException {

        if(url.contains("?")){
            url=url+"&";
        }else{
            url=url+"?";
        }

        JspWriter out=this.getJspContext().getOut();
        StringBuffer stringBuffer=new StringBuffer();
        stringBuffer.append("首页");
        stringBuffer.append("上一页");
        stringBuffer.append("下一页");
        stringBuffer.append("尾页");
        stringBuffer.append("共"+pageInfo.getTotal()+"条");

        out.print(stringBuffer.toString());



    }
}

WEB-INF创建fenye.tld

package com.utils;

import com.github.pagehelper.PageInfo;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;

public class FenyeUtil extends SimpleTagSupport {

    private String url;//请求地址
    private PageInfo pageInfo;//保存分页所需的数据

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public PageInfo getPageInfo() {
        return pageInfo;
    }

    public void setPageInfo(PageInfo pageInfo) {
        this.pageInfo = pageInfo;
    }

    @Override
    public void doTag() throws JspException, IOException {

        if(url.contains("?")){
            url=url+"&";
        }else{
            url=url+"?";
        }

        JspWriter out=this.getJspContext().getOut();
        StringBuffer stringBuffer=new StringBuffer();
        stringBuffer.append("首页");
        stringBuffer.append("上一页");
        stringBuffer.append("下一页");
        stringBuffer.append("尾页");
        stringBuffer.append("共"+pageInfo.getTotal()+"条");

        out.print(stringBuffer.toString());



    }
}

使用方法

<%@taglib prefix="fy" uri="http://java.sun.com/jsp/femye/fy" %>



你可能感兴趣的:(工具类)