日期:2014-05-20 浏览次数:20867 次
package www.gbsou.com.pagination; import java.io.Serializable; /** * 分页对象 * @author www.gbsou.com */ public class Page implements Serializable{ private Boolean hasPrePage; private Boolean hasNextPage; /** * total count in a page.When less than 1(zero or minus), it will not * paging. */ private int pageSize; private int totalPage; private int totalRecord; private int currentPage; /** * the begin index in total record for current page */ private int beginIndex; /** * @roseuid 46C0080B02C8 */ public Page(boolean hasPrePage, boolean hasNextPage, int pageSize, int totalPage, int totalRecord, int currentPage, int beginIndex) { this.hasPrePage = hasPrePage; this.hasNextPage = hasNextPage; this.pageSize = pageSize; this.totalPage = totalPage; this.totalRecord = totalRecord; this.currentPage = currentPage; this.beginIndex = beginIndex; } public Page() { } public int getBeginIndex() { return beginIndex; } public void setBeginIndex(int beginIndex) { this.beginIndex = beginIndex; } public int getCurrentPage() { return currentPage; } public void setCurrentPage(int currentPage) { this.currentPage = currentPage; } public Boolean hasNextPage() { return hasNextPage; } public void setHasNextPage(Boolean hasNextPage) { this.hasNextPage = hasNextPage; } public Boolean hasPrePage() { return hasPrePage; } public void setHasPrePage(Boolean hasPrePage) { this.hasPrePage = hasPrePage; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } public int getTotalPage() { return totalPage; } public void setTotalPage(int totalPage) { this.totalPage = totalPage; } public int getTotalRecord() { return totalRecord; } public void setTotalRecord(int totalRecord) { this.totalRecord = totalRecord; } }
------解决方案--------------------
这个数据库层 就用hibernate的
openSession().createQuery("").setFirstResult(1).setMaxResults(10).list()咯
------解决方案--------------------
如果是用ssh的话,那么关于分页的支持,spring提供的hibernate支持类里面已经提供两个方法,你只要传两个参数就OK了。这样你在逻辑层和数据层之间只是对传递两个参数,但是对于分页,这两个参数是必须的。具体的代码就像一楼的代码那样,但是有些计算其实也是可以放到这个model中的,比如只要给了总记录数,和每页要显示的数,那么剩下的计算,比如有多少页之类的,都是在这个model里面自动完成的。
------解决方案--------------------
------解决方案--------------------
--包
create or replace package pkg_query as
type cur_query is ref cursor;
end pkg_query;
--过程
CREATE OR REPLACE PROCEDURE "PRC_QUERY" (p_tableName
in varchar2, --表名
p_strWhere in varchar2, --查询条件
p_orderColumn in varchar2, --排序的列
p_orderStyle in varchar2, --排序方式
p_curPage in out Number, --当前页
p_pageSize in out Number, --每页显示记录条数
p_totalRecords out Number, --总记录数
p_totalPages out Number, --总页数
v_cur out pkg_query.cur_query) --返回的结果集
IS
v_sql VARCHAR2(1000) := ''; --sql语句
v_startRecord Number(4); --开始显示的记录条数
v_endRecord Number(4); --结束显示的记录条数
BEGIN
--记录中总记录条数
v_sql := 'SELECT TO_NUMBER(COUNT(*)) FROM ' || p_tableName || ' WHERE 1=1';
IF p_strWhere IS NOT NULL or p_strWhere <> '' THEN
v_sql := v_sql || p_strWhere;
END IF;