struts2+pager-taglib分页 本是可以显示 首页 1 2 3 尾页 但是 我只显示 首页 1 尾页来
action:
public class OrgAction extends ActionSupport implements ModelDriven{
private Organization org;
private PageModel pm;
private List<Organization> orgs;
private OrgDTO orgDto = new OrgDTO();
private int offset;
private HttpServletRequest request = ServletActionContext.getRequest();
ApplicationContext cxt = new ClassPathXmlApplicationContext("beans.xml");
OrgManager orgManager = (OrgManager) cxt.getBean("orgManager");
//采用每页多少个 进行显示 来分页
public String list() {
pm = orgManager.findOrgs(orgDto.getParentId(), 0, 4);
orgs = pm.getDatas();
System.out.println(pm.getTotal());
return "list";
}
************************
dao层:
//分页
public PageModel findOrgs(int parentId, int offset, int pagesize) {
//获得总记录数
String selectCountString = "select count(*) from Organization o where o.parent = null";
if(parentId != 0) {
selectCountString ="select count(*) from Organization o where o.parent.id =" + parentId;
}
int total = ((Long) this.getHibernateTemple().getSessionFactory().getCurrentSession()
.createQuery(selectCountString).uniqueResult()).intValue();
//获取当前页面的数据
String hql = "select o from Organization o where o.parent = null";
if(parentId != 0) {
hql = "select o from Organization o where o.parent.id = " + parentId;
}
List<Organization> datas = this.getHibernateTemple().getSessionFactory().getCurrentSession()
.createQuery(hql).setFirstResult(offset).setMaxResults(pagesize).list();
PageModel pm = new PageModel();
pm.setTotal(total);
pm.setDatas(datas);
return pm;
}
jsp:
<pg:pager url="org/org!findPage" items="${pm.total}" export="currentPageNumber=pageNumber">
<pg:param name="parentId"/>
<pg:first>
<a href="${pageUrl}">首页</a>
</pg:first>
<pg:prev>
<a href="${pageUrl}">前页</a>
</pg:prev>
<pg:pages>
<c:choose>
<c:when test="${currentPageNumber eq pageNumber}">
<font color="red">${pageNumber }</font>
</c:when>
<c:otherwise>
<a href="${pageUrl}">${pageNumber }</a>
</c:otherwise>
</c:choose>
</pg:pages>
<pg:next>
<a href="${pageUrl}">下页</a>
</pg:next>
<pg:last>
<a href="${pageUrl}">尾页</a>
</pg:last>
</pg:pager>
pageModel:
package com.java.cn.model;
import java.util.List;
public class PageModel {
private int total;
private List<Organization> datas;
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public List<Organization> getDatas() {
return datas;
}
public void setDatas(List<Organization> datas) {
this.datas = datas;
}
}