spring MongoDB 통합 (페이지)


 
첫 페이지 에 페이지 클래스 만 들 기
Pagination.java
 
package com.mkfree.framework.common.page;import java.util.List;/** *       * * @author hk * * 2012-10-26   8:23:15 */publicclassPagination{/** *       20  */privateint pageSize =20;/** *      */privateint pageNo;/** *     */privateint upPage;/** *     */privateint nextPage;/** *          */privatelong totalCount;/** *        */privateint totalPage;/** *      */privateListdatas;/** *    url */privateString pageUrl;/** *           * * @return */publicint getFirstResult(){return(this.getPageNo()-1)*this.getPageSize();}/** *          * * @return */publicint getLastResult(){returnthis.getPageNo()*this.getPageSize();}/** *         */publicvoid setTotalPage(){this.totalPage =(int)((this.totalCount %this.pageSize >0)?(this.totalCount /this.pageSize +1):this.totalCount /this.pageSize);}/** *        */publicvoid setUpPage(){this.upPage =(this.pageNo >1)?this.pageNo -1:this.pageNo;}/** *       */publicvoid setNextPage(){this.nextPage =(this.pageNo ==this.totalPage)?this.pageNo :this.pageNo +1;}publicint getNextPage(){return nextPage;}publicint getTotalPage(){return totalPage;}publicint getUpPage(){return upPage;}publicint getPageSize(){return pageSize;}publicvoid setPageSize(int pageSize){this.pageSize = pageSize;}publicint getPageNo(){return pageNo;}publicvoid setPageNo(int pageNo){this.pageNo = pageNo;}publiclong getTotalCount(){return totalCount;}publicvoid setTotalCount(long totalCount2){this.totalCount = totalCount2;}publicListgetDatas(){return datas;}publicvoid setDatas(Listdatas){this.datas = datas;}publicString getPageUrl(){return pageUrl;}publicvoid setPageUrl(String pageUrl){this.pageUrl = pageUrl;}publicPagination(int pageNo,int pageSize,long totalCount2){this.setPageNo(pageNo);this.setPageSize(pageSize);this.setTotalCount(totalCount2);this.init();}/** *         */privatevoid init(){this.setTotalPage();//       this.setUpPage();//      this.setNextPage();//      }}

그리고 우리 다시 보 자.
 
MongodbBaseDao. java 는 다음 페이지 의 코드 를 추가 하 였 습 니 다.
 
package com.mkfree.framework.common.mongodb;import java.util.List;import org.springframework.data.mongodb.core.MongoTemplate;import org.springframework.data.mongodb.core.query.Query;import org.springframework.data.mongodb.core.query.Update;import com.mkfree.framework.common.page.Pagination;/** * mongodb       * * @author oyhk * * 2013-1-22  5:28:26 */publicabstractclassMongodbBaseDao{/** *       ,       * * @param pageNo * @param pageSize * @param query * @return */publicPaginationgetPage(int pageNo,int pageSize,Query query){long totalCount =this.mongoTemplate.count(query,this.getEntityClass());Paginationpage=newPagination(pageNo, pageSize, totalCount); query.skip(page.getFirstResult());// skip           query.limit(pageSize);//  skip  ,      Listdatas=this.find(query); page.setDatas(datas);return page;}//.......    ,       }

come from internet
원본 코드 는 첨부 파일 참조

좋은 웹페이지 즐겨찾기