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


  • 相关阅读:
    Java中的String,StringBuilder,StringBuffer三者的区别
    安装ik分词器以及版本和ES版本的兼容性
    利用logstash从mysql同步数据到ElasticSearch
    安装logstash和logstash-input-jdbc
    mac 下安装ES 与 Head插件 以及安装Kibana
    数据库备份出现警告:Warning: Using a password on the command line interface can be insecure. Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even thos
    Mybatis 中$与#的区别
    spring boot Tomcat访问日志
    spring boot配置druid数据源和监控配置
    kafka基本概念
  • 原文地址:https://www.cnblogs.com/li2beyond/p/8315286.html
Copyright © 2011-2022 走看看