This commit is contained in:
Dftre 2024-07-21 16:05:53 +08:00
commit f6f5a1cdff
2 changed files with 7 additions and 3 deletions

View File

@ -14,6 +14,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.DefaultResourceLoader;
import com.github.pagehelper.PageInterceptor;
import com.github.pagehelper.autoconfigure.PageHelperStandardProperties;
import com.ruoyi.common.interceptor.mybatis.CreateSqlSessionFactory; import com.ruoyi.common.interceptor.mybatis.CreateSqlSessionFactory;
import com.ruoyi.common.utils.MybatisUtils; import com.ruoyi.common.utils.MybatisUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
@ -30,7 +32,7 @@ public class MyBatisConfig {
@Bean @Bean
@ConditionalOnProperty(prefix = "createSqlSessionFactory", name = "use", havingValue = "mybatis") @ConditionalOnProperty(prefix = "createSqlSessionFactory", name = "use", havingValue = "mybatis")
public CreateSqlSessionFactory createSqlSessionFactory() { public CreateSqlSessionFactory createSqlSessionFactory(PageHelperStandardProperties packageHelperStandardProperties) {
return new CreateSqlSessionFactory() { return new CreateSqlSessionFactory() {
public SqlSessionFactory createSqlSessionFactory(Environment env, DataSource dataSource) throws Exception { public SqlSessionFactory createSqlSessionFactory(Environment env, DataSource dataSource) throws Exception {
String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage"); String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
@ -45,6 +47,9 @@ public class MyBatisConfig {
sessionFactory.setMapperLocations( sessionFactory.setMapperLocations(
MybatisUtils.resolveMapperLocations(StringUtils.split(mapperLocations, ","))); MybatisUtils.resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation)); sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
PageInterceptor interceptor = new PageInterceptor();
interceptor.setProperties(packageHelperStandardProperties.getProperties());
sessionFactory.addPlugins(interceptor);
return sessionFactory.getObject(); return sessionFactory.getObject();
} }
}; };

View File

@ -31,7 +31,6 @@ public class SqlSessionFactoryConfig {
for (Map.Entry<String, DataSource> entry : targetDataSources.entrySet()) { for (Map.Entry<String, DataSource> entry : targetDataSources.entrySet()) {
SqlSessionFactory sessionFactory = createSqlSessionFactory.createSqlSessionFactory(env, entry.getValue()); SqlSessionFactory sessionFactory = createSqlSessionFactory.createSqlSessionFactory(env, entry.getValue());
sqlSessionFactoryMap.put(entry.getKey(), sessionFactory); sqlSessionFactoryMap.put(entry.getKey(), sessionFactory);
// 应对热重载的特殊处理 // 应对热重载的特殊处理
Object ret = com.atomikos.icatch.config.Configuration.removeResource(entry.getKey()); Object ret = com.atomikos.icatch.config.Configuration.removeResource(entry.getKey());
if (ret != null) { if (ret != null) {