81,092
社区成员
发帖
与我相关
我的任务
分享
<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">30</property>
<property name="c3p0.timeout">1800</property>
<property name="c3p0.max_statements">50</property>
int totalRows = 0;// 记录总行数
totalRows = userBiz.getRows();
Pager pager = PagerHelper.getPager(request, totalRows);
List list = userBiz.getAllAusers(pager.getPageSize(), pager
.getStartRow());
System.out.print(list.isEmpty());
System.out.print(totalRows);
request.setAttribute("item", list);
request.setAttribute("pager", pager);
request.setAttribute("totalRows", totalRows);
return mapping.findForward("select");
<form id="form1" name="form1" action="guodu.do" method="post">
<html:hidden property="state" value="getStudents" />
<table width="595" border="1" align="center" name="table"
id="mytable" cellspacing="0">
<tr>
<td colspan="9" align="center">
<h2>
<input type="button" value="导出" onclick="preview()"
class="smallInput">
<input type="button" name="Submit2" value="首页"
onclick="tijiao2()" class="smallInput" />
</h2>
</td>
</tr>
<tr>
<td width="60" align="center">
姓名
</td>
<td width="90" align="center">
部门
</td>
<td width="120" align="center">
岗位
</td>
<td width="80" align="center">
工号
</td>
<td width="45" align="center">
内线
</td>
<td width="80" align="center">
办公电话
</td>
<td width="80" align="center">
移动电话
</td>
<td width="80" align="center">
QQ
</td>
</tr>
<logic:notEmpty name="item" scope="request">
<logic:iterate id="list" name="item">
<%--<c:forEach items="${page.pageList}" var="list">
--%>
<tr>
<td align="center">
${list.name}
</td>
<td align="center">
${list.section}
</td>
<td align="center">
${list.station}
</td>
<td align="center">
${list.jnumber}
</td>
<td align="center">
${list.insideLance}
</td>
<td align="center">
${list.officePhone}
</td>
<td align="center">
${list.telephone}
</td>
<td align="center">
${list.qq}
</td>
</tr>
</logic:iterate>
<%--</c:forEach>
--%>
</table>
</logic:notEmpty>
<table border="1" align="center" style="width: 500px">
<tr>
<td colspan="8" align="right" class="head">
第
<bean:write name="pager" property="currentPage" />
页 共
<bean:write name="pager" property="totalPages" />
页
<html:link action="guodu.do?state=getStudents&pageMethod=first"
paramName="pager" paramProperty="currentPage"
paramId="currentPage">首页</html:link>
<html:link
action="guodu.do?state=getStudents&pageMethod=previous"
paramName="pager" paramProperty="currentPage"
paramId="currentPage">上一页</html:link>
<html:link action="guodu.do?state=getStudents&pageMethod=next"
paramName="pager" paramProperty="currentPage"
paramId="currentPage">下一页</html:link>
<html:link action="guodu.do?state=getStudents&pageMethod=last"
paramName="pager" paramProperty="currentPage"
paramId="currentPage">尾页</html:link>
</td>
<td>
共有
<%=request.getAttribute("totalRows")%>
条记录
</td>
</tr>
</table>
// pageSize是设置数据库每次返回多少条数据 startRow是设置每页从第几条数据开始
public List getAllAusers(int pageSize, int startRow) throws Exception {
Session session=this.getSession();
String hql="from Auser";
Query query=session.createQuery(hql);
query.setFirstResult(startRow);
query.setMaxResults(pageSize);
return query.list();
}
// 获取返回数据个数
public int getRows()throws Exception{
Session session =this.getSession();
String hql="select count(*) from Auser";
Query q=session.createQuery(hql);
// 有时候uniqueResult()方法返回的是一个Long类型的变量而不是Integer类型的变量 原因是J2EE版本不一样 所以这里有必要进行一下类型转换
Long lo=(Long)q.uniqueResult();
Integer count=new Integer(String.valueOf(lo));
return count;
}
这是分页方法的实现类