以下是在前兩天一個項目中的分頁功能截取
BlogDAO
[java]
/** 根據條件(默認一張表所有數據)返回多條記錄 */
public List<Blog> list(String kw
List<Blog> list = null;
Integer limitaInteger = (pageCur
Integer limitbInteger = pageCur*pageSize;
Object[] params = {limitaInteger
String sqlWhere =
String sql =
if(kw!=null && !kw
sqlWhere =
}
sql += sqlWhere;
sql +=
ResultSetHandler<List<Blog》 rsh = new BeanListHandler<Blog>(Blog
try {
list = qr
} catch (SQLException e) {
e
}
return list;
}
BlogActin
[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) {
this
}
[java]
public Integer getPagenum() {
return pagenum;
}
public void setPagenum(Integer pagenum) {
this
}
列表方法
[java]
/** 顯示博客列表信息 */
public String alllist() {
request=ServletActionContext
blogtopic=request
allblogs=blogDAO
num_allblog=untAllNum(blogtopic)
num_allblogpage=num_allblog/
return
}
JSP文件
[html]
<div class=
<c:forEach items=
<div class=
<h
<a name=
<dl>
<dt><a #
<dd><div class=
<p><div class=
<a class=
<a class=
<div class=
<div align=
<table width=
<tr>
<td width=
<a Blog_getContent
<a Blog_getContent
<td width=
</tr></table></span></div>
</div>
</div>
</c:forEach>
</div>
<div class=
<span> ${num_allblog}條數據 共${num_allblogpage}頁 </span>
<c:forEach begin=
[<a Blog_alllist
</c:forEach>
<a Blog_alllist
<a Blog_alllist
</div>
From:http://tw.wingwit.com/Article/program/Java/ky/201311/27879.html