HBase的分頁實現相對複雜一些。核心思想是結合分頁過濾器PageFilter(pageSize)和查詢設置開始行scan.setStartRow(lastRow),lastRow爲上一次查詢rowkey,需要注意的是該rowkey是一個數組,對應多字段的存儲位置;
不同用戶登錄會產生不同lastRow,因此我們把lastRow存儲到session中,參考PageLastRowCache。
爲了解耦,我們又把對lastRow操作封裝到HBaseDaoImpl,以便開發寫代碼的時候不需要關心lastRow的操作。
public PageInfo searchXControl(QueryControlRuleQO qo,IntegerpageSize,Integer currteIndex) throwsException {
//條件過濾器
FilterList filterList = new QueryControlRuleFilterList(qo).getFilterList();
//獲得符合條件結果總數
Long total = getTotal(controlTableName, filterList);
//過濾器集合
FilterList fl=new FilterList();
//分頁過濾器
Filterfilter = new PageFilter(pageSize);
fl.addFilter(filterList);
fl.addFilter(filter);
//封裝結果集
List<XControl> list = getList(XControl.class, controlTableName, fl, currteIndex);
log.info("--------------------- total : " + list.size());
//返回結果集
PageInfo page = new PageInfo(total, list);
return page;
}
更多精彩內容請關注:http://bbs.superwu.cn
關注超人學院微信二維碼:
關注超人學院java免費學習交流羣: