[u][b]1.分页工具Class:[/b][/u]
public class PageVo {
private int currentPage;//当前页
private int totalPage;//总页数
private int lastPage;//上一页
private int nextPage;//下一页
private static final int accountOfPage = 5;//每页显示几行
private int fromIndex;//每页从第几条开始
private int toIndex;//每页到第几条
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getLastPage() {
return lastPage;
}
public void setLastPage(int lastPage) {
this.lastPage = lastPage;
}
public int getNextPage() {
return nextPage;
}
public void setNextPage(int nextPage) {
this.nextPage = nextPage;
}
public int getFromIndex() {
return fromIndex;
}
public void setFromIndex(int fromIndex) {
this.fromIndex = fromIndex;
}
public int getToIndex() {
return toIndex;
}
public void setToIndex(int toIndex) {
this.toIndex = toIndex;
}
public static int getAccountofpage() {
return accountOfPage;
}
//分页方法
public void setFenYe(int currentPage, int totalAccount){
//
//totalPage = (totalAccount % accountOfPage) == 0?totalAccount/accountOfPage:totalAccount+1;
totalPage = (totalAccount % accountOfPage) == 0?totalAccount/accountOfPage:totalAccount/accountOfPage+1;
//如果当前页比总页数多
if(currentPage>totalPage){
currentPage = totalPage;
}
//如果当前页小于最小页
if(currentPage<1){
currentPage = 1;
}
//设置下一页
this.nextPage = currentPage + 1;
//
if(nextPage>totalPage){
nextPage = totalPage;
}
//设置上一页
this.lastPage = currentPage - 1;
if(lastPage < 1){
lastPage = 1;
}
//设置每页从第几条开始
fromIndex = (currentPage - 1)*accountOfPage;
if(fromIndex > totalAccount - 1){
fromIndex = totalAccount;//让最后一页为空
}
//设置每页的最后一条
toIndex = accountOfPage * currentPage;
if(toIndex > totalAccount){
toIndex = totalAccount;//让最后一页为空
}
}
}
[u][b]2.Dao方法:[/b][/u]
//计算数据库记录的总条数
int getTotalRecord();
//获取当前页记录
List<JlManager> queryLimitFuleJL(int fromIndex,int toIndex);
[u][b]3.实现类:[/b][/u]
public int getTotalRecord() {
return this.getHibernateTemplate().find("from JlManager").size();
}
public List<JlManager> queryLimitFuleJL(int fromIndex,int toIndex) {
List<JlManager> list = this.getHibernateTemplate().find("from JlManager").subList(fromIndex, toIndex);
return list;
}
[u][b]4.Action:[/b][/u]
public String fenye(){
if(page<1){
page = 1;
}
pageVo = new PageVo();
totalAccount = jiLiangIMP.getTotalRecord();
pageVo.setFenYe(page, totalAccount);
list = jiLiangIMP.queryLimitFuleJL(pageVo.getFromIndex(),pageVo.getToIndex());
//HttpServletRequest req = ServletActionContext.getRequest();
//req.setAttribute("", list);
return "jiliang";
}
[u][b]5.页面:[/b][/u]
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="33%">
<div align="left">
<span class="STYLE22"> 共有<strong><s:property value="totalAccount" />
</strong> 条记录,当前第<strong><s:property value="page" /></strong> 页,
共 <strong><s:property value="pageVo.totalPage" /></strong> 页</span>
</div>
</td>
<td width="67%">
<table width="312" border="0" align="right" cellpadding="0"
cellspacing="0">
<tr>
<td width="49">
<div align="center">
<!-- 首页 -->
<a href="<%=basePath%>/gdmis/RuchangJlAction!fenye.action?page=1">
首页</a>
</div>
</td>
<td width="49">
<div align="center">
<!--上一页 -->
<a href="<%=basePath%>/gdmis/RuchangJlAction!fenye.action?page=<s:property value="pageVo.lastPage" />">
上一页
</div>
</td>
<td width="49">
<div align="center">
<!--下一页 -->
<a href="<%=basePath%>/gdmis/RuchangJlAction!fenye.action?page=<s:property value="pageVo.nextPage" />">
下一页
</div>
</td>
<td width="49">
<div align="center">
<!-- 末页 -->
<a href="<%=basePath%>/gdmis/RuchangJlAction!fenye.action?page=<s:property value="pageVo.totalPage" />">
末页
</div>
</td>
<td width="37" class="STYLE22">
<div align="center">
转到
</div>
</td>
<td width="22">
<div align="center">
<!-- 通过id=“turnToId”再userCheckPage.js中进行 -->
<input type="text" name="textfield" id="turnToId"
style="width: 20px; height: 12px; font-size: 12px; border: solid 1px #7aaebd;" />
</div>
</td>
<td width="22" class="STYLE22">
<div align="center">
页
</div>
</td>
<td width="35">
<a href="#" οnclick="turnTo()">
<img src="<%=basePath%>images/main_62.gif" width="26"
height="15" /></a>
</td>
</tr>
</table>
</td>
</tr>
</table>
public class PageVo {
private int currentPage;//当前页
private int totalPage;//总页数
private int lastPage;//上一页
private int nextPage;//下一页
private static final int accountOfPage = 5;//每页显示几行
private int fromIndex;//每页从第几条开始
private int toIndex;//每页到第几条
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getLastPage() {
return lastPage;
}
public void setLastPage(int lastPage) {
this.lastPage = lastPage;
}
public int getNextPage() {
return nextPage;
}
public void setNextPage(int nextPage) {
this.nextPage = nextPage;
}
public int getFromIndex() {
return fromIndex;
}
public void setFromIndex(int fromIndex) {
this.fromIndex = fromIndex;
}
public int getToIndex() {
return toIndex;
}
public void setToIndex(int toIndex) {
this.toIndex = toIndex;
}
public static int getAccountofpage() {
return accountOfPage;
}
//分页方法
public void setFenYe(int currentPage, int totalAccount){
//
//totalPage = (totalAccount % accountOfPage) == 0?totalAccount/accountOfPage:totalAccount+1;
totalPage = (totalAccount % accountOfPage) == 0?totalAccount/accountOfPage:totalAccount/accountOfPage+1;
//如果当前页比总页数多
if(currentPage>totalPage){
currentPage = totalPage;
}
//如果当前页小于最小页
if(currentPage<1){
currentPage = 1;
}
//设置下一页
this.nextPage = currentPage + 1;
//
if(nextPage>totalPage){
nextPage = totalPage;
}
//设置上一页
this.lastPage = currentPage - 1;
if(lastPage < 1){
lastPage = 1;
}
//设置每页从第几条开始
fromIndex = (currentPage - 1)*accountOfPage;
if(fromIndex > totalAccount - 1){
fromIndex = totalAccount;//让最后一页为空
}
//设置每页的最后一条
toIndex = accountOfPage * currentPage;
if(toIndex > totalAccount){
toIndex = totalAccount;//让最后一页为空
}
}
}
[u][b]2.Dao方法:[/b][/u]
//计算数据库记录的总条数
int getTotalRecord();
//获取当前页记录
List<JlManager> queryLimitFuleJL(int fromIndex,int toIndex);
[u][b]3.实现类:[/b][/u]
public int getTotalRecord() {
return this.getHibernateTemplate().find("from JlManager").size();
}
public List<JlManager> queryLimitFuleJL(int fromIndex,int toIndex) {
List<JlManager> list = this.getHibernateTemplate().find("from JlManager").subList(fromIndex, toIndex);
return list;
}
[u][b]4.Action:[/b][/u]
public String fenye(){
if(page<1){
page = 1;
}
pageVo = new PageVo();
totalAccount = jiLiangIMP.getTotalRecord();
pageVo.setFenYe(page, totalAccount);
list = jiLiangIMP.queryLimitFuleJL(pageVo.getFromIndex(),pageVo.getToIndex());
//HttpServletRequest req = ServletActionContext.getRequest();
//req.setAttribute("", list);
return "jiliang";
}
[u][b]5.页面:[/b][/u]
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="33%">
<div align="left">
<span class="STYLE22"> 共有<strong><s:property value="totalAccount" />
</strong> 条记录,当前第<strong><s:property value="page" /></strong> 页,
共 <strong><s:property value="pageVo.totalPage" /></strong> 页</span>
</div>
</td>
<td width="67%">
<table width="312" border="0" align="right" cellpadding="0"
cellspacing="0">
<tr>
<td width="49">
<div align="center">
<!-- 首页 -->
<a href="<%=basePath%>/gdmis/RuchangJlAction!fenye.action?page=1">
首页</a>
</div>
</td>
<td width="49">
<div align="center">
<!--上一页 -->
<a href="<%=basePath%>/gdmis/RuchangJlAction!fenye.action?page=<s:property value="pageVo.lastPage" />">
上一页
</div>
</td>
<td width="49">
<div align="center">
<!--下一页 -->
<a href="<%=basePath%>/gdmis/RuchangJlAction!fenye.action?page=<s:property value="pageVo.nextPage" />">
下一页
</div>
</td>
<td width="49">
<div align="center">
<!-- 末页 -->
<a href="<%=basePath%>/gdmis/RuchangJlAction!fenye.action?page=<s:property value="pageVo.totalPage" />">
末页
</div>
</td>
<td width="37" class="STYLE22">
<div align="center">
转到
</div>
</td>
<td width="22">
<div align="center">
<!-- 通过id=“turnToId”再userCheckPage.js中进行 -->
<input type="text" name="textfield" id="turnToId"
style="width: 20px; height: 12px; font-size: 12px; border: solid 1px #7aaebd;" />
</div>
</td>
<td width="22" class="STYLE22">
<div align="center">
页
</div>
</td>
<td width="35">
<a href="#" οnclick="turnTo()">
<img src="<%=basePath%>images/main_62.gif" width="26"
height="15" /></a>
</td>
</tr>
</table>
</td>
</tr>
</table>