Page主要应用于静态的页面,而Story则应用于动态性的文章,比如部门的新闻,对于个人博客网站,如果是单人博客的话,一般用Story作为博客。Page没有节点的发布信息,而Story有。
Page默认是不会被推到首页的,而Story默认被推到首页。Page默认是禁止评论的,而Story则允许评论。从这几点可以看出,Story更具有交互性。
不明白你说的这个page类是不是指分页的公共类。分页大概的原理分两种1、依靠数据库做分页(每次查询若干条),2、依靠缓存来做分页(一次将数据全取出来,然后将结果集分成若干页)。你要根据需求来考虑哪种方案更适合。
page类主要需要定义几个参数(当前页,总页数,每页显示多少条),然后定义几个方法(上一页,下一页,首页,尾页等),然后查询的时候将数据传进去就可以了。下面给你一个例子:
package com.ccsee.aat.util
import javax.servlet.http.*
import java.util.*
import org.apache.log4j.*
/**
* Title:分页组件
* Description:分页组件
* Copyright: Copyright (c) 2010
* @author
* @version 1.0
*/
public class PageBean {
// 初始化Log
private static Logger logger = Logger.getLogger(PageBean.class)
public PageBean() {
}
/**
*
* 对查询数据封装
*/
private ArrayList objList = new ArrayList()
/**
* 页面记录大小
*/
private int pageSize = 20
/**
* 总行数
*/
private int rowcnt
/**
* 当前页码
*/
private int currentPage
/**
* 分页信息
*/
private String pageInfo
/**
* 获得当前页
*
* @return
*/
public int getCurrentPage() {
return currentPage
}
/**
* 设置当前页
*
* @param currentPage
*/
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage
}
/**
* 得到页面大小
*
* @return
*/
public int getPageSize() {
return pageSize
}
/**
* 设置页面大小
*
* @param pageSize
*/
public void setPageSize(int pageSize) {
this.pageSize = pageSize
}
/**
* 得到数据
*
* @return
*/
public ArrayList getObjList() {
return objList
}
/**
* 设置数据
*
* @param objList
*/
public void setObjList(ArrayList objList) {
this.objList = objList
}
/**
* 设置页面信息
*
* @param pageInfo
*/
public void setPageInfo(String pageInfo) {
this.pageInfo = pageInfo
}
/**
* 实现下拉框数字翻页
*
* @param pageNum
*当前页号
* @param lastPageNum
*总的页号
* @return
*/
private String getSelect(int pageNum, int lastPageNum) {
String select = "跳到<select name=temp onchange=\"prePage(this.value)\">"
select = select + "<option value=" + pageNum + ">" + pageNum
+ "</option>"
for (int i = 1i <= lastPageNumi++) {
if (i != pageNum) {
select = select + "<option value=" + i + ">" + i + "</option>"
}
}
select = select + "</select>页"
return select
}
/**
* 获取翻页信息
*
* @param
* @return
*/
public String getPageInfo() {
int previousPageNum = currentPage - 1
int nextPageNum = currentPage + 1
int pageCount = rowcnt % this.pageSize
if (pageCount == 0) {
pageCount = rowcnt / pageSize
} else {
pageCount = rowcnt / pageSize + 1
}
if (pageCount <1) {
pageCount = 1
}
pageInfo = "当前第<font color=\"red\">" + currentPage
+ "</font>页&nbsp&nbsp共<font color=\"red\">" + pageCount
+ "</font>页&nbsp&nbsp"
String first = "<a href =\"#\" onclick=\"prePage('" + 1
+ "')\">首页&nbsp</a>"
String previous = "<a href =\"#\" onclick=\"prePage('"
+ previousPageNum + "')\">前一页&nbsp</a>"
String next = "<a href =\"#\" onclick=\"prePage('" + nextPageNum
+ "')\">下一页&nbsp</a>"
String last = "<a href =\"#\" onclick=\"prePage('" + pageCount
+ "')\">末页</a>"
if (currentPage != 1) {
pageInfo = pageInfo.concat(first).concat(previous)
}
if (currentPage != pageCount) {
pageInfo = pageInfo.concat(next).concat(last)
}
pageInfo = pageInfo + getSelect(currentPage, pageCount)
pageInfo += " <input name=\"pagenum\" type=\"hidden\">\r\n"
String script = "<script>\r\n"
script += "function prePage(pageNum){\r\n"// document.all["pageNum"].value=pageNum
script += "document.all[\"pagenum\"].value=pageNum\r\n"
script += "document.forms[0].submit()\r\n"
script += "}\r\n"
script += "</script>"
pageInfo = pageInfo + script
return pageInfo == null ? "" : pageInfo
}
/**
* 获取翻页信息
*
* @param
* @return
*/
public String getPageInfo2() {
int previousPageNum = currentPage - 1
int nextPageNum = currentPage + 1
int pageCount = rowcnt % this.pageSize
if (pageCount == 0) {
pageCount = rowcnt / pageSize
} else {
pageCount = rowcnt / pageSize + 1
}
if (pageCount <1) {
pageCount = 1
}
pageInfo = "当前第<font color=\"red\">" + currentPage
+ "</font>页&nbsp&nbsp共<font color=\"red\">" + pageCount
+ "</font>页&nbsp&nbsp"
String first = "<a href =\"#\" onclick=\"prePage('" + 1
+ "')\">首页</a> "
String previous = "<a href =\"#\" onclick=\"prePage('"
+ previousPageNum + "')\">前一页</a> "
String next = "<a href =\"#\" onclick=\"prePage('" + nextPageNum
+ "')\">下一页</a> "
String last = "<a href =\"#\" onclick=\"prePage('" + pageCount
+ "')\">末页</a> <input type=\"hidden\" name=\"nextPage\" id=\"nextPage\"/>"
if (currentPage != 1) {
pageInfo = pageInfo.concat(first).concat(previous)
}
if (currentPage != pageCount) {
pageInfo = pageInfo.concat(next).concat(last)
}
pageInfo = pageInfo + getSelect(currentPage, pageCount)
pageInfo += " <input name=\"pagenum\" id='pagenum' type=\"hidden\">\r\n"
String script = "<script>\r\n"
script += "function prePage(pageNum){\r\n"// document.all["pageNum"].value=pageNum
script += "document.getElementById('pagenum').value = '' + pageNum\r\n"
script += "document.forms[0].submit()\r\n"
script += "}\r\n"
script += "</script>"
pageInfo = pageInfo + script
return pageInfo == null ? "" : pageInfo
}
/**
* 设置当前页码
*
* @param httpServletRequest
*/
public void setPageNum(HttpServletRequest httpServletRequest) {
String pageNum = httpServletRequest.getParameter("pagenum")
try {
this.setCurrentPage(Integer.parseInt(pageNum))
} catch (Exception ex) {
this.setCurrentPage(1)
}
}
/**
* 得到总行数
*
* @return
*/
public int getRowcnt() {
return rowcnt
}
/**
* 设置总行数
*
* @param rowcnt
*/
public void setRowcnt(int rowcnt) {
this.rowcnt = rowcnt
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)