easyuUI实现客户分页显示逻辑分析

页面

前端

前端easyUI,自带分页功能,添加pagination属性
前端会传给后端两个属性:

  • page:当前页码
  • rows:每页显示记录数

后端

  • 接收page和rows参数
  • 根据参数分页查询
  • 获取结果
  • 返回给页面(total:总记录数;rows:当前页数据列表)

后台使用pageHelper分页插件

  • 导入pagehelper-5.1.2.jar及依赖jar包jsqlparser-1.0.jar
  • 在applicationContext.xml配置注册pagehelper插件

使用easyui的datagrid分页时遇到的错误

错误描述:

严重: Servlet.service() for servlet [DispatcherServlet] in context with path [/CRM] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.NullPointerException
### Cause: java.lang.NullPointerException] with root cause
java.lang.NullPointerException
	at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:147)
	at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)

解决方法

/**
 * 查询分页数据,给页面返回json格式数据
 * 
 * @return
 */
@ResponseBody
@RequestMapping("/listByPage")
public Map<String, Object> listByPage(Integer page, Integer rows) {

	PageHelper.startPage(page, rows);

	List<Customer> list = customerService.selectList();
	// 使用PageInfo封装查询结果
	PageInfo<Customer> pageInfo = new PageInfo<>(list);

	// 从PageInfo对象中取出查询结果
	long total = pageInfo.getTotal();
	List<Customer> custList = pageInfo.getList();

	map.put("total", total);
	map.put("rows", custList);

	return map;
}

将从pageInfo中取得的的结果存入map时,将对应的结果(custList)的键改为rows,如果不是rows,可能会报此错误。

posted on 2019-09-24 21:58  行之间  阅读(385)  评论(0编辑  收藏  举报