zoukankan      html  css  js  c++  java
  • easyUI-SSM分页技术

    分页(pageHelper插件)

    后台实现步骤:
    1、在parent工程中添加pagehelper管理包(版本5.12)
    在mapper(dao层)工程中加pagehelper依赖包;
    2、在web项目Mybatis的配置文件配置sqlMapConfig.xml文件(mybatis-config.xml)
    内容:
    <plugins><!--配置pagehelper插件-->
    <plugin interceptor="com.github.pagehelper.PageInterceptor">
    <!-- 此处省略,有db的url自动识别 -->
    <!-- <property name="dialect" value="mysql"></property> -->
    </plugin>
    </plugins>
    3、 在spring-mybatis.xml中给sqlSessionFactory添加属性
    <!-- 配置mybatis的分页插件 -->
    <property name="configLocation" value="classpath:mybatis/sqlMapConfig.xml">
    </property>

    4、在utils工程中写公共的pojo

    package com.j17.common.pojo;

    import java.util.List;
    /**
    *封装datagrid插件的响应数据格式
    * @author Administrator
    *
    */
    public class DataGridResult {

    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;
    }

    @Override
    public String toString() {
    return "DataGridResult [total=" + total + ", rows=" + rows + "]";
    }
    }

    5、实现service中的分页方法

    @Override
    public DataGridResult findItemByPage(Integer page, Integer pageSize) {
    //默认example对象,以此为条件的查询是全表查
    TbItemExample example = new TbItemExample();
    //设置分页特征
    //此句放置与原始查询前,会将院查询转为带分页特征的查询,交给执行单元继续执行
    PageHelper.startPage(page, pageSize);
    List<TbItem> items = itemMapper.selectByExample(example);//执行查询
    DataGridResult result = new DataGridResult();
    result.setRows(items);
    //获取分页信息
    PageInfo info= new PageInfo<>(items);
    long total = info.getTotal();//得到总记录数
    result.setTotal(total);
    return result;
    }
    6、controller层

    /**
    *
    * @param pageNum
    * 当前页码
    * @param pageSize
    * 每页记录数
    * @return
    */
    @RequestMapping(value = "/items", method = RequestMethod.POST)
    @ResponseBody
    public DataGridResult showItemPages(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
    @RequestParam(value = "rows", defaultValue = "10") Integer pageSize) {

    DataGridResult result = itemService.findItemByPage(pageNum, pageSize);
    return result;
    }


  • 相关阅读:
    .NET MVC后台发送post请求
    (整理)Sublime Text 3 安装、破解、安装Package Control、汉化、添加到右键菜单、代码格式化、禁止更新
    百度api查询多个地址的经纬度的问题
    try{}里有一个 return 语句,那么紧跟在这个 try 后的 finally {}里的 code 会 不会被执行,什么时候被执行,在 return 前还是后?
    js获取某个日期所在周周一的日期
    重学C++ (1)
    基于.NET平台常用的框架整理
    指针常量和常量指针的区别
    C++四种强制类型转换关键字
    const define 定义常量的区别
  • 原文地址:https://www.cnblogs.com/li2beyond/p/8315286.html
Copyright © 2011-2022 走看看