DB

@MapperScan

  1. 直接在Mapper类上面添加注解@Mapper,这种方式要求每一个mapper类都需要添加此注解,麻烦。
  2. 通过使用@MapperScan可以指定要扫描的Mapper类的包的路径,比如
@Configuration
@MapperScan(basePackages = {"com.segment.dao", "com.segment.new.dao"})
public class MainDataSourceConfig {

    @Bean(name = "mybatisSlowSqlInterceptor")
    public MybatisSlowSqlInterceptor mybatisSlowSqlInterceptor() {
        return new MybatisSlowSqlInterceptor();
    }

    @Primary
    @Bean(name = "mainDataSource")
    @ConfigurationProperties("spring.datasource.druid")
    public DataSource accountDataSource() {
        DruidDataSource druidDataSource = DruidDataSourceBuilder.create().build();
        //druidDataSource.setTimeBetweenLogStatsMillis(3000);
        return druidDataSource;
    }

    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    /**
     * 注入sql注入器
     */
    @Bean
    public ISqlInjector sqlInjector(){
        return new AggSqlInjector();
    }
}

hizengzeng
177 声望10 粉丝

hizengzeng