紧急修复!!mybatis分页问题

This commit is contained in:
dftre 2024-07-18 10:49:00 +08:00
parent 39b8586bfd
commit 769e4574ff
2 changed files with 10 additions and 4 deletions

View File

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

View File

@ -1,6 +1,7 @@
package com.ruoyi.framework.config;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
@ -25,13 +26,13 @@ public class SqlSessionFactoryConfig {
DynamicDataSourceProperties dataSourceProperties;
@Bean(name = "sqlSessionTemplate")
public DynamicSqlSessionTemplate sqlSessionTemplate(Environment env) throws Exception {
public DynamicSqlSessionTemplate sqlSessionTemplate(Environment env,List<SqlSessionFactory> sqlSessionFactoryList) throws Exception {
Map<Object, SqlSessionFactory> sqlSessionFactoryMap = new HashMap<>();
Map<String, DataSource> targetDataSources = dataSourceProperties.getTargetDataSources();
for (Map.Entry<String, DataSource> entry : targetDataSources.entrySet()) {
SqlSessionFactory sessionFactory = createSqlSessionFactory.createSqlSessionFactory(env, entry.getValue());
sqlSessionFactoryList.add(sessionFactory);
sqlSessionFactoryMap.put(entry.getKey(), sessionFactory);
// 应对热重载的特殊处理
Object ret = com.atomikos.icatch.config.Configuration.removeResource(entry.getKey());
if (ret != null) {