要格式化显示数据,又写不好自己的分页程序。不如试试displaytag标签。displaytag即可以进行几十万条的数据同时加载进行分页又可以定制自己的样式。当然它还有许多其他的功能,因为使用时间不长。我也不太清楚.这里只讲它的分页功能就好了。
要用displaytag标签进行动态数据分页,在WEB工程的LIB里加入displaytag.jar。然后在JSP页面里加入这句代码就可以使用displaytag标签了。
<%@ taglib uri="http://displaytag.sf.net/el" prefix="display" %>
要分页显示肯定得有这么几步是少不了的
1.工具类或者分页类。2.准备数据。3.绑定数据的JSP
实现思路:可以自己写个包装类用于你要进行分页显示的BEAN。也就是上面提到的第一步类似一个工具类.源码如下:
import org.displaytag.decorator.TableDecorator;
public class Wrapper extends TableDecorator {
public String getDeptId(){
Demo organise = (Demo)getCurrentRowObject();
String demoid = organise.getId();
if(demoid==null){
demoid="";
}
StringBuffer htmlStr = new StringBuffer();
htmlStr.append("<div align='center'><a href='../organization/deptEdit.htm?parentId=");//在这里加//一句这样的代码可以对单条记录进行修改。
htmlStr.append(organise.getId());
htmlStr.append("'>");
htmlStr.append(demoid);
htmlStr.append("</a></div>");
return htmlStr.toString();
}
}
2.准备数据:
在ACTION里或者controller取得业务逻辑层传递过来的数据并绑定在request作用域里。
HttpSession session = (HttpSession)request.getSession(true);
String pageListSize = (String)session.getAttribute("PAGE_LIST_SIZE");
String type = request.getParameter("operation");
if (pageListSize == null) {
session.setAttribute("PAGE_LIST_SIZE", "10");
pageListSize = "10";
}
if(type.equals("zx")){
List list = dataSource.getData();
request.setAttribute("operation","zx");
request.setAttribute("list",list);
}
if(type.equals("gd")){
List list = dataSource.getGlist();
request.setAttribute("list",list);
request.setAttribute("operation","gd");
}
request.setAttribute("pageListSize",pageListSize);
return new ModelAndView(getCustomUrl());
3.绑定数据
<c:if test="${operation == 'gd'}">
<c:if test="${!empty list}">
<div style="height:680;width:100%;overflow:auto;">
<table bgcolor="#6F9DD9" border="0" width="100%" cellpadding="0"
cellspacing="0">
<tr>
<td colspan="4" align=center bgcolor=red>
工单列表
</td>
</tr>
<tr>
<td>
<display:table id="dept" name="list" pagesize="${pageListSize}" class="table_changecolor" style="width:100%" cellspacing="1"
requestURI="${path}/user/list.htm" decorator="com.ultrapower.test.web.Wrapper">
<tr class="even">
<td>
<display:column title="ID" property="deptId"
sortable="true" style="width:30%;cursor: hand" class="content_back1"/>
</td>
</tr>
</table>
<input type="button" value=" 返回 "
οnclick="invokeIndxe();"/>
</div>
</c:if>
</c:if>
自此就可以使用displaytag进行应用的分页显示了。