java jquery mongodb/mysql 分页

java 分页
   页面函数 
   function searchHistory(page,disR){
		var fn = arguments.callee;
		var req = $('#f_1').serialize() + '&page='+(page||1)+'&displayRecord='+(disR=disR||10)+"&replyCode="+1 + "&ran="+Math.random();//默认10
		$.post("/data/listDistributorInfos.do", req, function(json) {
			if(json.success !== true){
				//提示报错
				alert(json.message);
			} else{
				var count 	= json.object.count,
				list 		= json.object.lists,
				p 			= json.object.page,
				pCount 		= json.object.pageCount;

				var $tbody = $('#J_tbody'), $box = $('#box');
				var html = '';
				$.each(list,function(i,n){
					var status_class = "";
					if(n.status == 1){
						status_class = "closed";
					}
					var time1 = "";
					if(n.createTime != null){
						var temp = new Date(n.createTime);
						time1 = temp.Format("yyyy-MM-dd");
					}
					var text = "<tr class='" + status_class + "'>"+
					"<td><a href='/gift/giftView.jspx?id=" + n.distributor_name +"'>"+  n.distributor_name  + "</a>"+'</td>' +
					'<td>'+n.deposit_num+'</td>'+
					'<td>'+222+'</td>'+
					'<td>'+n.activation_num+'</td>'+
					'<td>'+n.trading_num+'</td>'+
					'<td>'+n.distributor_gift_id+'</td>'+
					"<td><a href=\"/distributor/viewAndEditDistributor.jspx?distributor_name=" + n.distributor_name + "\">详细</a></td>"+
					'</tr>';
					if(null != text && text != ""){
						html += text;
					}
				});
				$tbody.html(html);
				var sort = $('#tr_head').find('td')
				//$('#count').html(" | 记录数("+count+")");

				//分页
				var $pag=$box.find('.paginationbar'),$dis=$box.find('.displayNum');
				$.sysop.pagination.init($pag,p,pCount,10,function(num){
					fn(num,disR);
				});
				//显示数目
				$.sysop.pagination.displayNum($dis,disR,function(){
					fn(1,this.innerHTML.slice(0,-1));
				});
			}
		});
	}


	$('#searchF').bind('click',function(){
		searchHistory(undefined,$.crm.getPageSize(), true);
	});
	$(function(){
		backAutoFillForm.init('#searchF','#f_1');// 提交按钮 表单
		searchPrize();
	});

	$('#add').bind('click',function(){
		window.location="/distributor/addDistributor.jspx";
	});
$.sysop 一类函数详见 附件 jquery.sysop.zip 


  mysql 分页controller
  @MethodResourceDesc(name = "[data]获取代理商列表")
	@RequestMapping(value = "/data/listDistributorInfos.do")
	@ResponseBody
	public Result listAdvertisSet(HttpServletRequest request,HttpServletResponse response){
		Result result = new Result();
		try{
			/*Query query = CRMQueryHelper.makeDistributorInfoQuery(
					RequestHelper.getQueryFields(request, CommercialDistributor.DISTRIBUTOR_NAME),
					 CommercialDistributor.CREATE_TIME, Order.DESCENDING);*/

			//int allCount = (int)commercialDistributorService.allCount(query);
			int pageSize = RequestHelper.getPageSize(request);
			if(0 == pageSize){
				pageSize = 20;
			}

//			List<CommercialDistributor> list = distributorInfoService.list(
//					query.skip(
//							(RequestHelper.getPageIndex(request) - 1) * pageSize
//							).limit(pageSize));
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("page", (RequestHelper.getPageIndex(request) - 1) * pageSize);
			map.put("pageSize", pageSize);
			map.put("distributorName", RequestHelper.getQueryFields(request, "distributorName"));
			List<DistributorConsumeResult> list = commercialDistributorService.listCommercialDistributor(map);
			/*List<CommercialDistributor> list = commercialDistributorService.list(
					query.skip(
							(RequestHelper.getPageIndex(request) - 1) * pageSize
							).limit(pageSize));*/

			int allCount = (int)commercialDistributorService.allCount();

			PagingVO pagingObject = new PagingVO();
			pagingObject.setPageCount((allCount + pageSize) / pageSize);
			pagingObject.setPage(RequestHelper.getPageIndex(request));
			pagingObject.setCount(allCount);
			pagingObject.setLists(list);
			result.setCode(ResultCode.SUCCESS);
			result.setObject(pagingObject);

		}catch(Exception e){
			result.setMessage(e.getMessage());
			logger.error(e.getMessage());
		}
		return result;
	}


mongodb 分页 controller 
  @MethodResourceDesc(name = "[data]获取代理商列表")
	@RequestMapping(value = "/data/listDistributorInfos.do")
	@ResponseBody
	public Result listAdvertisSet(HttpServletRequest request,HttpServletResponse response){
		Result result = new Result();
		try{
			Query query = CRMQueryHelper.makeDistributorInfoQuery(
					RequestHelper.getQueryFields(request, CommercialDistributor.DISTRIBUTOR_NAME),
					 CommercialDistributor.CREATE_TIME, Order.DESCENDING);*/

			int allCount = (int)commercialDistributorService.allCount(query);
			int pageSize = RequestHelper.getPageSize(request);
			if(0 == pageSize){
				pageSize = 20;
			}
			
			List<CommercialDistributor> list = commercialDistributorService.list(
					query.skip(
							(RequestHelper.getPageIndex(request) - 1) * pageSize
							).limit(pageSize));

			PagingVO pagingObject = new PagingVO();
			pagingObject.setPageCount((allCount + pageSize) / pageSize);
			pagingObject.setPage(RequestHelper.getPageIndex(request));
			pagingObject.setCount(allCount);
			pagingObject.setLists(list);
			result.setCode(ResultCode.SUCCESS);
			result.setObject(pagingObject);

		}catch(Exception e){
			result.setMessage(e.getMessage());
			logger.error(e.getMessage());
		}
		return result;
	}

result PagingVO 详见 Result_PagingVO


你可能感兴趣的:(mongodb)