Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改 PageInterceptor 的注册方式 #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pagehelper-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<parent>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot</artifactId>
<version>1.2.3</version>
<version>1.2.4-SNAPSHOT</version>
</parent>
<artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
<name>pagehelper-spring-boot-autoconfigure</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,13 @@
package com.github.pagehelper.autoconfigure;

import com.github.pagehelper.PageInterceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

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

/**
Expand All @@ -45,17 +40,9 @@
* @author liuzh
*/
@Configuration
@ConditionalOnBean(SqlSessionFactory.class)
@EnableConfigurationProperties(PageHelperProperties.class)
@AutoConfigureAfter(MybatisAutoConfiguration.class)
public class PageHelperAutoConfiguration {

@Autowired
private List<SqlSessionFactory> sqlSessionFactoryList;

@Autowired
private PageHelperProperties properties;

/**
* 接受分页插件额外的属性
*
Expand All @@ -67,18 +54,24 @@ public Properties pageHelperProperties() {
return new Properties();
}

@PostConstruct
public void addPageInterceptor() {
PageInterceptor interceptor = new PageInterceptor();
Properties properties = new Properties();
//先把一般方式配置的属性放进去
properties.putAll(pageHelperProperties());
//在把特殊配置放进去,由于close-conn 利用上面方式时,属性名就是 close-conn 而不是 closeConn,所以需要额外的一步
properties.putAll(this.properties.getProperties());
interceptor.setProperties(properties);
for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) {
sqlSessionFactory.getConfiguration().addInterceptor(interceptor);
}
@Bean
public ConfigurationCustomizer pageHelperConfigurationCustomizer() {
return new ConfigurationCustomizer() {
@Autowired
private PageHelperProperties properties;

@Override
public void customize(org.apache.ibatis.session.Configuration configuration) {
PageInterceptor interceptor = new PageInterceptor();
Properties properties = new Properties();
//先把一般方式配置的属性放进去
properties.putAll(pageHelperProperties());
//在把特殊配置放进去,由于close-conn 利用上面方式时,属性名就是 close-conn 而不是 closeConn,所以需要额外的一步
properties.putAll(this.properties.getProperties());
interceptor.setProperties(properties);
configuration.addInterceptor(interceptor);
}
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-samples</artifactId>
<version>1.1.1</version>
<version>1.2.4-SNAPSHOT</version>
</parent>
<artifactId>pagehelper-spring-boot-sample-annotation</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-samples</artifactId>
<version>1.1.1</version>
<version>1.2.4-SNAPSHOT</version>
</parent>
<artifactId>pagehelper-spring-boot-sample-xml</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion pagehelper-spring-boot-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<parent>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot</artifactId>
<version>1.2.3</version>
<version>1.2.4-SNAPSHOT</version>
</parent>
<artifactId>pagehelper-spring-boot-samples</artifactId>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion pagehelper-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<parent>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot</artifactId>
<version>1.2.3</version>
<version>1.2.4-SNAPSHOT</version>
</parent>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<name>pagehelper-spring-boot-starter</name>
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot</artifactId>
<version>1.2.3</version>
<version>1.2.4-SNAPSHOT</version>
<packaging>pom</packaging>

<name>pagehelper-spring-boot</name>
Expand Down Expand Up @@ -63,10 +63,10 @@
</modules>

<properties>
<mybatis.version>3.4.4</mybatis.version>
<mybatis.version>3.4.5</mybatis.version>
<pagehelper.version>5.1.2</pagehelper.version>
<mybatis-spring-boot.version>1.3.1</mybatis-spring-boot.version>
<spring-boot.version>1.5.7.RELEASE</spring-boot.version>
<spring-boot.version>1.5.8.RELEASE</spring-boot.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down