页面

前端

前端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,可能会报此错误。

最新文章

  1. eclipse下创建maven项目
  2. dsfgsdfg
  3. css中font-size的单位总结:px、em、pt
  4. oracle如何获取每个月的最后一天
  5. Linux中环境变量文件及配置(转载)
  6. OGNL表达式(待解答)
  7. 50 Android Hacks阅读笔记
  8. easyui的datagrid实例实现
  9. sky A800s手机恢复出厂设置操作
  10. bzoj 4278 [ONTAK2015]Tasowanie(SA,贪心)
  11. 转摘:常用ubuntu 关机,重启,注销命令
  12. 在Delphi中,关于数组名称
  13. 结构体dict_index_t;
  14. 从键盘输入当月利润I,求应发放奖金总数?
  15. input、button、a标签 等定义的按钮尺寸的兼容性问题
  16. navcat无法远程连接mysql数据库解决办法
  17. 《JAVA程序设计》_第四周学习总结
  18. JQuery的常用选择器 转
  19. zabbix3监控php-fpm的状态
  20. Shell 脚本格式注意事项

热门文章

  1. 3、Shiro授权
  2. 让hibernate支持mysql的text或者longtext
  3. 阶段3 1.Mybatis_05.使用Mybatis完成CRUD_3 Mybatis的CRUD-修改和删除操作
  4. 测开之路一百二十八:flask之重定向和404
  5. Service层获取HttpServletRequest request
  6. HTML——超级链接 表格 框架
  7. idea中怎么去查看maven项目的依赖包是否有冲突
  8. vue2.0父子组件通信以及同级组件通信
  9. 第十三周学习总结 Java的异常
  10. qt undefined reference to `vtable for subClass&#39;