1.引架包
<!--javaee,处理自定义标签--> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency>
2.在WEB-INF中创建.tld.文件,加入需引用的属性
<?xml version="1.0" encoding="UTF-8" ?> <taglib> <tlib-version>1.1</tlib-version> <jsp-version>2.0</jsp-version> <short-name>fy</short-name> <uri>http://java.sun.com/jsp/fenye/fy</uri> <tag> <name>fy</name> <tag-class>com.ly.util.FeiyeUtil</tag-class> <body-content>empty</body-content>//标签之间的内容为空 <attribute> <name>url</name> <required>true</required>//必须的 <type>java.lang.String</type>//类型 <rtexprvalue>true</rtexprvalue>//支持EL表达式 </attribute> <attribute> <name>pageinfo</name> <type>com.github.pagehelper.PageInfo</type> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib>
3.创建工具处理类extends SimpleTagSupport
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 { JspWriter out=this.getJspContext().getOut(); StringBuffer stringBuffer=new StringBuffer(); stringBuffer.append("<a href=‘"+url+"&index=1&size="+pageInfo.getPageSize()+"‘>首页</a>"); stringBuffer.append("<a href=‘"+url+"&index="+(pageInfo.getPrePage()==0?1:pageInfo.getPrePage())+"&size="+pageInfo.getPageSize()+"‘>上一页</a>"); stringBuffer.append("<a href=‘"+url+"&index="+(pageInfo.getNextPage()==0?pageInfo.getPages():pageInfo.getNextPage())+"&size="+pageInfo.getPageSize()+"‘>下一页</a>"); stringBuffer.append("<a href=‘"+url+"&index="+pageInfo.getPages()+"&size="+pageInfo.getPageSize()+"‘>尾页</a>"); stringBuffer.append("共"+pageInfo.getTotal()+"条"); out.print(stringBuffer.toString()); } }
原文地址:https://www.cnblogs.com/yunshao/p/9833812.html
时间: 2024-11-11 21:29:59