別兩句話回答,麻煩講詳細點,要足夠應付面試官
2 回答

大咪
TA貢獻785條經(jīng)驗 獲得超332個贊
mysql的我比較清楚,oracle的沒有實現(xiàn)過不太清楚,但感覺應該也差不多吧。。。
首先呢要先創(chuàng)建對應的PageBean實體類啦,代碼如下:
public?class?PageBean<T>?{ private?int?currPage;//當前頁數(shù) private?int?pageSize;//每頁顯示的記錄數(shù) private?int?totalCount;//總記錄數(shù) private?int?totalPage;//總頁數(shù) private?List<T>?list;//每頁顯示的數(shù)據(jù) public?int?getCurrPage()?{ return?currPage; } public?void?setCurrPage(int?currPage)?{ this.currPage?=?currPage; ......各種getter?and??setter?方法,這里直接省略了 }
然后是接收當前頁數(shù)的代碼:
//接收當前頁數(shù) private?int?currPage?=?1; public?void?setCurrPage(int?currPage)?{ this.currPage?=?currPage; }
然后是分頁查詢的方法:
????//這部分代碼是比較重要的 //分頁查詢部分的方法 @Override public?PageBean<Department>?findByPage(Integer?currPage)?{ PageBean<Department>?pageBean?=?new?PageBean<Department>(); //封裝當前頁數(shù) pageBean.setCurrPage(currPage); //封裝每頁顯示記錄數(shù) int?pageSize?=?3; pageBean.setPageSize(pageSize); //封裝總記錄數(shù) int?totalCount?=?departmentDao.findCount(); pageBean.setTotalCount(totalCount); //封裝總頁數(shù) double?tc?=?totalCount; Double?num?=?Math.ceil(tc?/?pageSize); pageBean.setTotalPage(num.intValue()); //封裝每頁顯示的數(shù)據(jù) int?begin?=?(currPage?-1)*?pageSize; List<Department>?list?=?departmentDao.findByPage(begin,?pageSize); pageBean.setList(list); return?pageBean; }
比如接下來我要分頁查詢的是部門管理的分頁,然后代碼
/** *分頁查詢部門? */ public?List<Department>?findByPage(int?begin,int?pageSize)?{ DetachedCriteria?critertia?=?DetachedCriteria.forClass(Department.class); List<Department>?list?=?this.getHibernateTemplate().findByCriteria(critertia,?begin,?pageSize); return?list; }
基本上全是代碼,我覺得理解了代碼比我說的要容易的多吧。。自己看下吧
添加回答
舉報
0/150
提交
取消