zoukankan      html  css  js  c++  java
  • Spring 中PageHelper分页插件使用

    1、增加pagehelper

     <!-- mybatis pager -->
        <dependency>
          <groupId>com.github.pagehelper</groupId>
          <artifactId>pagehelper</artifactId>
          <version>4.1.0</version>
        </dependency>
    

      

    2、增加配置

    <!--Spring和MyBatis整合-->
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource" />
            <!--自动扫描mapping.xml文件-->
            <property name="mapperLocations" value="classpath:mappers/*.xml"></property>
    
            <!-- 分页插件 -->
            <property name="plugins">
                <array>
                    <bean class="com.github.pagehelper.PageHelper">
                        <property name="properties">
                            <value>
                                dialect=oracle
                            </value>
                        </property>
                    </bean>
                </array>
            </property>
    
        </bean>
    

      

    3、Service中实现

      public PageInfo<Log> queryList(int pageNum, int pageSize){
            PageHelper.startPage(pageNum,pageSize);
            List<Log> list = xxMapperDao.queryList();
            PageInfo<Log> pageInfo = new PageInfo<>(list);
            return  pageInfo;
        }
    

      

    4、Controller中调用

     @RequestMapping(value = "queryLogs.htm")
        public void queryLogs( HttpServletResponse response,
                                 @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                                 @RequestParam(value = "pageSize",defaultValue = "10")int pageSize){
            PageInfo<Log> list =  iLogService.queryList(pageNum, pageSize);
            ...
    
        }
    

      

  • 相关阅读:
    Linux学习之查看是否安装软件
    Linux学习之nfs实例
    Linux学习之nfs安装配置
    Linux 学习之防火墙配置
    Linux学习之系统时间同步
    Linux学习之守护进程详解
    Linux学习之Center os网络配置
    Linux学习之挂载操作
    Linux学习之挂载
    Linux学习之开机启动
  • 原文地址:https://www.cnblogs.com/linlf03/p/9996160.html
Copyright © 2011-2022 走看看