pagehelper springboot整合与使用

16 篇文章 0 订阅
4 篇文章 0 订阅

https://www.cnblogs.com/Oliver-rebirth/p/springboot_pagehelper.html
https://www.cnblogs.com/charlypage/p/11220755.html

pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments: true
pagehelper.params: pageNum=page.index;pageSize=page.rows;count=countSql;reasonable=reasonable;pageSizeZero=pageSizeZero



mavem

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>5.1.2</version>
</dependency>

在这里插入图片描述
MybatisPluginConfiguration

package com.sdyy.springboot.config;

import com.github.pagehelper.PageInterceptor;

import org.apache.ibatis.session.SqlSessionFactory;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;

/**
 * @author g1558
 * @date 2019-10-08-13:25
 */
@Configuration

public class MybatisPluginConfiguration {

    @Autowired
    private List<SqlSessionFactory> sqlSessionFactoryList;
    @Autowired
    private PageHelperProperties properties;
   // @Autowired
   // private ISqlBuilderSelector sqlBuilderSelector;

    public MybatisPluginConfiguration() {
    }


    @PostConstruct
    public void addPageInterceptor() {
        PageInterceptor interceptor = new PageInterceptor();
        Properties properties = new Properties();
        properties.putAll(this.properties.getProperties());
        interceptor.setProperties(properties);
      //  DataPermissionInterceptor permissionInterceptor = new DataPermissionInterceptor();
      //  permissionInterceptor.setSqlBuilderSelector(sqlBuilderSelector);
        Iterator var3 = this.sqlSessionFactoryList.iterator();
        while(var3.hasNext()) {
            SqlSessionFactory sqlSessionFactory = (SqlSessionFactory)var3.next();
            sqlSessionFactory.getConfiguration().addInterceptor(interceptor);
          //  sqlSessionFactory.getConfiguration().addInterceptor(permissionInterceptor);

        }

    }
}

PageHelperProperties

package com.sdyy.springboot.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Properties;

/**
 * @author g1558
 * @date 2019-10-08-13:26
 */
@Component
@ConfigurationProperties(prefix = "pagehelper")
public class PageHelperProperties {
    public static final String PAGEHELPER_PREFIX = "pagehelper";
    private Properties properties = new Properties();

    public PageHelperProperties() {
    }

    public Properties getProperties() {
        return this.properties;
    }

    public String getOffsetAsPageNum() {
        return this.properties.getProperty("offsetAsPageNum");
    }

    public void setOffsetAsPageNum(String offsetAsPageNum) {
        this.properties.setProperty("offsetAsPageNum", offsetAsPageNum);
    }

    public String getRowBoundsWithCount() {
        return this.properties.getProperty("rowBoundsWithCount");
    }

    public void setRowBoundsWithCount(String rowBoundsWithCount) {
        this.properties.setProperty("rowBoundsWithCount", rowBoundsWithCount);
    }

    public String getPageSizeZero() {
        return this.properties.getProperty("pageSizeZero");
    }

    public void setPageSizeZero(String pageSizeZero) {
        this.properties.setProperty("pageSizeZero", pageSizeZero);
    }

    public String getReasonable() {
        return this.properties.getProperty("reasonable");
    }

    public void setReasonable(String reasonable) {
        this.properties.setProperty("reasonable", reasonable);
    }

    public String getSupportMethodsArguments() {
        return this.properties.getProperty("supportMethodsArguments");
    }

    public void setSupportMethodsArguments(String supportMethodsArguments) {
        this.properties.setProperty("supportMethodsArguments", supportMethodsArguments);
    }

    public String getDialect() {
        return this.properties.getProperty("dialect");
    }

    public void setDialect(String dialect) {
        this.properties.setProperty("dialect", dialect);
    }

    public String getHelperDialect() {
        return this.properties.getProperty("helperDialect");
    }

    public void setHelperDialect(String helperDialect) {
        this.properties.setProperty("helperDialect", helperDialect);
    }

    public String getAutoRuntimeDialect() {
        return this.properties.getProperty("autoRuntimeDialect");
    }

    public void setAutoRuntimeDialect(String autoRuntimeDialect) {
        this.properties.setProperty("autoRuntimeDialect", autoRuntimeDialect);
    }

    public String getAutoDialect() {
        return this.properties.getProperty("autoDialect");
    }

    public void setAutoDialect(String autoDialect) {
        this.properties.setProperty("autoDialect", autoDialect);
    }

    public String getCloseConn() {
        return this.properties.getProperty("closeConn");
    }

    public void setCloseConn(String closeConn) {
        this.properties.setProperty("closeConn", closeConn);
    }

    public String getParams() {
        return this.properties.getProperty("params");
    }

    public void setParams(String params) {
        this.properties.setProperty("params", params);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值