zoukankan      html  css  js  c++  java
  • 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,可能会报此错误。

  • 相关阅读:
    CSS 中 nth-child 和 nth-of-type 的区别
    Git HTTPS 方式自动保存用户名密码
    nginx 配置代理某个路径
    VS Code 常用插件列表
    安装node-sass的正确姿势【转】
    MongoDB 3.4.2 配置 CentOS 6.5 远程连接
    CentOS 6.5 升级 PHP 到5.6
    常用正则表达式整理[JavaScript]
    nginx提示413 Request Entity Too Large解决方法
    Linux远程执行Shell命令或脚本
  • 原文地址:https://www.cnblogs.com/zxfei/p/11581426.html
Copyright © 2011-2022 走看看