以下是在前两天一个项目中的分页功能截取
BlogDAOjava文件
[java]
/** 根据条件(默认一张表所有数据)返回多条记录 */
public List<Blog> list(String kwInteger pageCurInteger pageSize) {
List<Blog> list = null;
Integer limitaInteger = (pageCur)*pageSize;
Integer limitbInteger = pageCur*pageSize;
Object[] params = {limitaIntegerlimitbInteger};//代入的参数列表
String sqlWhere = ;
String sql = select * from csdn_blog where first= ;
if(kw!=null && !kwequals()) {
sqlWhere = and topic like %+kw+%;
}
sql += sqlWhere;
sql += order by id desc limit ??;
ResultSetHandler<List<Blog》 rsh = new BeanListHandler<Blog>(Blogclass)//把结果集转成BeanList
try {
list = qrquery(getConn() sql rsh params) //调用查询接口的查询函数
} catch (SQLException e) {
eprintStackTrace()
}
return list;
}
BlogActinjava文件
[java]
private Integer pagenum;//页码
[java] view plaincopy
private List<Blog> allblogs;
并提供set get 方法
[java]
public List<Blog> getAllblogs() {
return allblogs;
}
public void setAllblogs(List<Blog> allblogs) {
thisallblogs = allblogs;
}
[java]
public Integer getPagenum() {
return pagenum;
}
public void setPagenum(Integer pagenum) {
thispagenum = pagenum;
}
列表方法
[java]
/** 显示博客列表信息 */
public String alllist() {
request=ServletActionContextgetRequest()
blogtopic=requestgetParameter(blogtopic)
allblogs=blogDAOlist(blogtopic pagenum )
num_allblog=untAllNum(blogtopic)
num_allblogpage=num_allblog/+;
return index;
}
JSP文件
[html]
<div class=content>
<c:forEach items=${allblogs} var=allblog>
<div class=blog_list>
<h><a # class=category>[${allblogtopic}]</a>
<a name= Blog_getContentaction?id=${allblogid} target=_blank>${allblogtitle}</a></h>
<dl>
<dt><a #><img src=img/oyuntaolianwujpg alt=jackyvincefu></a></dt>
<dd><div class=text_length><pre>${ntent }</pre></div></dd></dl>
<p><div class=lable>
<a class=tag #>C++</a><a class=tag # target=_blank>指针常量</a>
<a class=tag #>常量指针</a><a class=tag # target=_blank>常量指针常量</a></div></p>
<div class=about_info>
<div align=left><span class=fl>
<table width= border=>
<tr>
<td width=><a # target=_blank class=user_name><font size=>${allblogwriter}</font></a>
<a Blog_getContentaction?id=${allblogid} target=_blank class=view><font size=>阅读(${allblogreader})</font></a>
<a Blog_getContentaction?id=${allblogid}#lookcomment target=_blank class=comment><font size=>评论(${allblogdiscuss})</font></a></td>
<td width= align=right><span class=time><font size=>${allblogtime}</font></span></td>
</tr></table></span></div>
</div>
</div>
</c:forEach>
</div>
<div class=page_nav>
<span> ${num_allblog}条数据 共${num_allblogpage}页 </span>
<c:forEach begin= end=${num_allblogpage} var=pagenum>
[<a Blog_alllistaction?pagenum=${pagenum}>${pagenum}</a>]
</c:forEach>
<a Blog_alllistaction?pagenum=${pagenum+}> 下一页 </a>
<a Blog_alllistaction?pagenum=${num_allblogpage}> 尾页</a> </div>
</div>