郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.gkhy.safePlatform.config.database;
 
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.stereotype.Repository;
 
import javax.sql.DataSource;
 
@Configuration
@MapperScan(basePackages = "com.gkhy.safePlatform.specialWork",sqlSessionTemplateRef = "sqlTemplateSpecialWork",
        annotationClass =
        Repository.class)
public class MyBatisConfigSpecialWork {
 
    @Autowired
    @Qualifier("dsSpecialWork")
    DataSource dsSpecialWork;
 
    @Autowired
    private MybatisPlusInterceptor mybatisPlusInterceptor;
 
    @Bean(name = "sqlFactorySpecialWork")
    public SqlSessionFactory sqlSessionFactory()
            throws Exception
    {
        MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
        factoryBean.setDataSource(dsSpecialWork);
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        factoryBean.setMapperLocations(resolver.getResources("classpath*:config/mapper/specialWork/**Mapper.xml"));
        //设置分页插件
        Interceptor[] plugins = {mybatisPlusInterceptor};
        factoryBean.setPlugins(plugins);
        return factoryBean.getObject();
    }
 
        @Bean(name = "sqlTemplateSpecialWork")
    public SqlSessionTemplate sqlSessionTemplate() throws Exception {
        return new SqlSessionTemplate(sqlSessionFactory());
    }
 
}