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);
        }
  • 相关阅读:
    jQuery弹出层插件大全:
    JavaScript数组去重的几种方法
    sql去除重复列(行)
    VS无法启动调试
    .将DayOfWeek转换成中文的几种方式
    关于 uniqueidentifier
    链接服务器
    我的目标:系统架构师
    异常(1)
    Visual C++开发工具与调试技巧整理
  • 原文地址:https://www.cnblogs.com/fengjunming/p/7782979.html
Copyright © 2011-2022 走看看