zoukankan      html  css  js  c++  java
  • spring-boot 集合mybatis 的分页查询

    spring-boot 集合mybatis 的github分页查询

    一、依赖包

     <!-- mysql 数据库驱动. -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>    
            
        <!--     
                spring-boot mybatis依赖:
                
                请不要使用1.0.0版本,因为还不支持拦截器插件,
                1.1.1大家使用最新版本即可
        -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.1.1</version>
        </dependency>
        
        <!-- 分页
            MyBatis提供了拦截器接口,我们可以实现自己的拦截器,
            将其作为一个plugin装入到SqlSessionFactory中。 
         -->    
       <!--分页-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>4.1.0</version>
        </dependency>    

     二、加入PageHelper

    @Configuration
    public class MyBatisConfiguration {
        
       @Bean
        public PageHelper pageHelper() {
            System.out.println("MyBatisConfiguration.pageHelper()");
            PageHelper pageHelper = new PageHelper();
            Properties p = new Properties();
            p.setProperty("offsetAsPageNum", "true");
            p.setProperty("rowBoundsWithCount", "true");
            p.setProperty("reasonable", "true");
            pageHelper.setProperties(p);
            return pageHelper;
        }
    }

     三

    @SpringBootApplication
    @MapperScan("com.fjm.*")  //扫描该目录下的文件
    public class App {
        public static void main(String[] args) {
             SpringApplication.run(App.class, args);
        }
    
    }

     四、在controller查询方法中加入PageHelper

    public List<User> find(Map map)
        {
            //添加分页查询条件
            PageHelper.startPage(0, 2);
            return userService.find(null);
        }
  • 相关阅读:
    KlayGE 4.0功能规划
    Kinect for Windows SDK发布
    CENTOS下用syslogng集中管理日志并压缩保存
    Eclipse+Plugin
    struts2 获取request、session的方法
    ActiveMQ使用经验
    springmock + dbutil 用来测试数据库操作
    英语学习
    如何查看eclipse版本
    jQuery插件的开发
  • 原文地址:https://www.cnblogs.com/fengjunming/p/7782979.html
Copyright © 2011-2022 走看看