zoukankan      html  css  js  c++  java
  • spring boot集成pagehelper(两种方式)

    当spring boot集成好mybatis时候需要进行分页,我们首先添加maven支持

    <dependency>
     <groupId>com.github.pagehelper</groupId>
     <artifactId>pagehelper</artifactId>
     <version>5.1.2</version>
    </dependency>
    <dependency>
     <groupId>com.github.pagehelper</groupId>
     <artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
     <version>1.2.3</version>
    </dependency>
    <dependency>
     <groupId>com.github.pagehelper</groupId>
     <artifactId>pagehelper-spring-boot-starter</artifactId>
     <version>1.2.3</version>
    </dependency>

    方式一:我们在application.yml(spring 需要读取的yml)中加入

    pagehelper:
     helperDialect: mysql
     reasonable: true
     supportMethodsArguments: true
     params: count=countSql

    然后重启即可。

    配置文件最终会被java所读取,最终注入到spring bean中,所以我们方法二是配置其bean类,热加载方便修改当然方式一更简单,

    方式二:在注解涵盖package下面新建PageHeleperConfig

    import com.github.pagehelper.PageHelper;
    import java.util.Properties;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
     
    /**
     * @author zhuxiaomeng
     * @date 2018/1/2.
     * @email 154040976@qq.com
     */
    @Configuration
    public class PageHelperConfig {
     
     
     @Bean
     public PageHelper getPageHelper(){
     PageHelper pageHelper=new PageHelper();
     Properties properties=new Properties();
     properties.setProperty("helperDialect","mysql");
     properties.setProperty("reasonable","true");
     properties.setProperty("supportMethodsArguments","true");
     properties.setProperty("params","count=countSql");
     pageHelper.setProperties(properties);
     return pageHelper;
     }
     
    }

    pageHelper 基础知识为:

    import com.github.pagehelper.Page;
    import com.github.pagehelper.PageHelper;
  • 相关阅读:
    [LeetCode] 303. 区域和检索
    [LeetCode] 120. 三角形最小路径和 ☆☆☆(动态规划 范例)
    [LeetCode] 18. 四数之和 ☆☆☆(双指针)
    [LeetCode] 16. 最接近的三数之和 ☆☆☆(双指针)
    [LeetCode] 109. 有序链表转换二叉搜索树 ☆☆☆(递归)
    优惠券模块设计要点
    nginx upstream 实现负载均衡
    nginx fastcgi配置
    nginx rewrite规则
    nginx Location 配置
  • 原文地址:https://www.cnblogs.com/deityjian/p/11099467.html
Copyright © 2011-2022 走看看