zoukankan      html  css  js  c++  java
  • pagehelper配置 多数据源自动切换数据库方言 mysql/sqlserver/oracle等数据库

    1 加入依赖

    <dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>5.1.10</version>
    </dependency>
    2、配置分页插件

    import com.github.pagehelper.PageInterceptor;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import java.util.Properties;
    /**
    * 描述:分页组件设置
    *
    * @author: Adobe Chow
    * @date: 2019/11/4 10:24
    * @Copyright: www.winshang.com Inc. All rights reserved.
    */
    @Configuration
    public class PageHelperConfig {

    @Bean
    PageInterceptor pageInterceptor(){
    PageInterceptor pageInterceptor = new PageInterceptor();
    Properties properties = new Properties();
    properties.setProperty("offsetAsPageNum","false");
    properties.setProperty("rowBoundsWithCount","false");
    properties.setProperty("pageSizeZero","true");
    properties.setProperty("reasonable","false");
    properties.setProperty("supportMethodsArguments","false");
    properties.setProperty("returnPageInfo","none");
    properties.setProperty("autoRuntimeDialect","true");
    pageInterceptor.setProperties(properties);
    return pageInterceptor;
    }

    }

    或者配置mybatis-config.xml

    <plugins>
    <plugin interceptor="com.github.pagehelper.PageInterceptor">
    <property name="offsetAsPageNum" value="false" />
    <property name="rowBoundsWithCount" value="false" />
    <property name="pageSizeZero" value="true" />
    <property name="reasonable" value="false" />
    <property name="supportMethodsArguments" value="false" />
    <property name="returnPageInfo" value="none" />
    <!--<property name="dialect" value="mysql" />-->
    <property name="autoRuntimeDialect" value="true" />
    <!--<property name="autoDialect" value="true" />-->
    </plugin>
    </plugins>

    使用

    @ResponseBody
    @PostMapping("myActivityList")
    public PageInfo myActivityList(@RequestBody ActivityListDto dto){
    PageHelper.startPage(1,10);
    return new PageInfo(activityManagerService.myActivityList(dto));
    }

  • 相关阅读:
    redis 批量删除key
    控制台直接执行sql语句
    item2 快捷键
    mac mamp环境 PHP命令行反应缓慢解决
    composer gitlab 搭建私包
    PostgreSql命令
    maven 程序包com.sun.image.codec.jpeg
    lumen配置日志daily模式
    PHPStorm怎么修改选中的背景颜色呢?
    vim 配置文件.vimrc,高亮+自动缩进+行号+折叠+优化
  • 原文地址:https://www.cnblogs.com/liangmm/p/12068392.html
Copyright © 2011-2022 走看看