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);
        }
  • 相关阅读:
    Dapper笔记-Dapper.Common【转】
    ASP.Net Core WebApi几种版本控制对比【转】
    ASP.NET Core WebAPI使用Swagger生成文档
    K8S笔记-Pod介绍【未完成】
    Docker-容器命令
    MySQL笔记-备份命令(mysqldump)
    MySQL笔记-INFORMATION_SCHEMA数据库介绍【转】
    Quartz.net笔记-计划任务触发器(Cron Trigger)
    Quartz.net笔记-简单触发器(Simple Trigger)
    Type序列化器
  • 原文地址:https://www.cnblogs.com/fengjunming/p/7782979.html
Copyright © 2011-2022 走看看