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

  • 相关阅读:
    20160402_[转]联合体(union)的使用方法及其本质
    20160402_C语言位操作符的使用
    20160402_多道程序环境中的设备抢占问题
    20160402_TCP/IP协议簇
    20160402_TCP连接的建立、终止和状态转换
    20160402_C++中的内存对齐
    20160127_Android程序完全退出的方法
    Redis持久化
    github慢!怎么办?
    mybatis-plus-generator: 自动生成entity,mapper,service,controller的代码
  • 原文地址:https://www.cnblogs.com/zxfei/p/11581426.html
Copyright © 2011-2022 走看看