MongoDB简单的分页查询加EasyUi,前台页面的展示

首先定义一个Table当载体

<!-- 查询 -->
    <table id="goodsTable"></table>

script:代码模块

//页面加载事件
$(function(){
	initFindGoodList();
})

//分页查询商品表
function initFindGoodList(){
	$("#goodsTable").datagrid({
		url:'../goods/findGoods.do',  //进入Controller后台进行查询
		//浏览器打开时加载 条查页面
		toolbar:'#toolbar',
		//屏幕自适应
		fit:true,
		//pagination开启分页,如果开启了easyui分页,默认会传2个参数。分别是page(第几页)和rows(每页多少条),默认是第一页,每页10条数据
		pagination:true,
		//自定义每页显示的条数
		pageSize:2,
		//自定义列表下拉框
		pageList:[2,4,10,15,20,40],
		columns:[[
            //field:代表的是你实体Bean的名字,title就是标题
			{field:"check",checkbox:true},
			//{field:'id',title:'id'},
			{field:'name',title:'商品名称'},
			{field:'count',title:'评论数量'},
			{field:'caozuo',title:'操作',formatter:function(value,row,index){
				return "<input type='button' value='查看评论' onclick='chakan(\""+row.id+"\")'>";
			}}
		]]		
	})
}

后台Controllrt层

//商品列表分页查询
//RequestMapping 你前台指向的路径
	@RequestMapping("findGoods")
	@ResponseBody
	public JSONObject findGoods(Integer page, Integer rows) {
		return goodsService.findGoods(page,rows);
	}

后台Service层

//查询商品分页列表
	@Override
	public JSONObject findGoods(Integer page, Integer rows) {
		Query query = new Query();
		JSONObject jsonObject = new JSONObject();
		//查询数量
		long total  = mongoTemplate.count(query,GoodsBean.class);
		//起始条数
		int start = (page-1)*rows;
		//分页
		query.skip(start).limit(rows);
		//查询数据
		List<GoodsBean> find = mongoTemplate.find(query, GoodsBean.class);
		//total总条数
		jsonObject.put("total", total);
        //rows查询出的数据
		jsonObject.put("rows", find);
		
		return jsonObject;
	}

分页就完成了,前台可以看到效果!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

听风动

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值