easyUI设置分页步骤(SSM框架)

版权声明:@CopyRight转载请注明出处 https://blog.csdn.net/LI_AINY/article/details/85373498
  1. 前端页面导入easyui所需要的css,js
<link rel="stylesheet" type="text/css"
	href="../lib/jquery-easyui-1.4.1/themes/gray/easyui.css" />
<link rel="stylesheet" type="text/css"
	href="../lib/jquery-easyui-1.4.1/themes/icon.css" />
  1. 按照需求建一个表格,从easyui复制一个分页控件过来修改一下即可
    其中field写的是你返回对象对应的字段,名称要一致
<table id="tt" class="easyui-datagrid" style="width:100%;height:auto"
		url="/findAllAdmin"  toolbar="#tb"
		title="建议列表" iconCls="icon-save"
		rownumbers="true" pagination="true">
	<thead>
		<tr>
			<th field="id" width="10%">管理员ID </th>
			<th field="name" width="10%">管理员名称</th>
			<th field="password" width="15%" align="right">管理员密码</th>
			<th field="power" width="15%" align="right">管理员权限</th>
			
		</tr>
	</thead>
</table>

请求路径在table里面写。

3.service层(加controller层)
3.1.Controler层:

package com.monster.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
/**
 * 
 * ClassName: AdminController <br/> 
 * Function: TODO ADD FUNCTION. <br/> 
 * Reason: TODO ADD REASON(可选). <br/> 
 * date: 2018年10月23日 下午4:40:52 <br/> 
 * 管理员
 * @author ljw
 * @version  
 * @since JDK 1.7
 */
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.monster.service.AdminService;
import com.monster.utils.EasyUIDataGridResult;
@Controller
public class AdminController {
		@Autowired
		private AdminService adminService;
		@RequestMapping("/findAllAdmin")
		@ResponseBody
		public EasyUIDataGridResult findAllAdmin(int page,int rows) {
			EasyUIDataGridResult findAllAdmin = adminService.findAllAdmin(page, rows);
			return findAllAdmin;
		}
}

3.2.Service层

package com.monster.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.monster.mapper.AdminMapper;
import com.monster.pojo.Admin;
import com.monster.pojo.AdminExample;
import com.monster.service.AdminService;
import com.monster.utils.EasyUIDataGridResult;
@Service
public class AdminServiceImpl implements AdminService{
		@Autowired 
		private AdminMapper adminMapper;
	@Override
	public EasyUIDataGridResult findAllAdmin(int pageNum, int pageSize) {
		// PageHelper Mybatis - 通用分页拦截器
		PageHelper.startPage(pageNum, pageSize);
		AdminExample example=new AdminExample();
		List<Admin> allAdmin = adminMapper.selectByExample(example);
		EasyUIDataGridResult dataGridResult = new EasyUIDataGridResult();
		PageInfo<Admin> pageInfo = new PageInfo<>(allAdmin);
		dataGridResult.setRows(allAdmin);
		dataGridResult.setTotal(pageInfo.getTotal());
		return dataGridResult;
	}

}

其中 PageHelper为Mybatis - 通用分页拦截器
PageInfo为对Page结果进行包装 ,新增分页的多项属性
  1. EasyUIDataGridResult类为自己设计的查询返回结果集
package com.monster.utils;

import java.io.Serializable;
import java.util.List;
/**
 * 分页
 * ClassName: EasyUIDataGridResult <br/> 
 * Function: TODO ADD FUNCTION. <br/> 
 * Reason: TODO ADD REASON(可选). <br/> 
 * date: 2018年10月28日 下午3:52:21 <br/> 
 * 
 * @author Foo Xiaoqiang 
 * @version  
 * @since JDK 1.7
 */
public class EasyUIDataGridResult implements Serializable{

	private long total;
	private List rows;
	public long getTotal() {
		return total;
	}
	public void setTotal(long total) {
		this.total = total;
	}
	public List getRows() {
		return rows;
	}
	public void setRows(List rows) {
		this.rows = rows;
	}
	
}

返回EasyUIDataGridResult类型的结果,前台页面分页控件就会自动实现分页

猜你喜欢

转载自blog.csdn.net/LI_AINY/article/details/85373498