在集成mybatis 和 tkmapper等时候,可以有两种选择,1,用springboot 的start 实现自动装配 2,普通的依赖形式,自己用@configure手动配置即可,无需开启
1 自动装配 (自动装配mapper,mybatis,pagehepler,pagehelper中有mybatis的依赖 所以mybatis的start无需写 )---自动装配中有好多重复依赖 看下有些可以省略
(例如分页插件中有mybatis)
=============
分页插件中就有依赖
//
//
//
//
//
mapper的自动装配 ---自动装配的主要工作就是修改默认配置
@SpringBootApplication
@EnableTransactionManagement
@MapperScan(basePackages = "com.houbank.bank.web.mapper")
public class BankWebApplication extends SpringBootServletInitializer{}
mapper.mappers=com.houbank.bank.web.util.MyMapper 自定义的通用mapper(注意自定的MyMapper不可以和普通的mapper放在一个路径中(否则框架扫描普通的时候会出错))
mapper.not-empty=false
mapper.identity=MYSQL
手动装配:
去了自动装配的start可以改用手动转配(处理依赖业务子项目的重复依赖,用底层的模块)
@Configuration
public class MyBatisMapperScannerConfig{
@Bean
public MapperScannerConfigurer mapperScannerConfigurer(){
MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");
mapperScannerConfigurer.setBasePackage("com.houbank.bank.mapper.dao");//扫描该路径下的dao
Properties properties = new Properties();
properties.setProperty("mappers", "com.houbank.bank.mapper.MyMapper");//通用dao
properties.setProperty("notEmpty", "false");
properties.setProperty("IDENTITY", "MYSQL");
mapperScannerConfigurer.setProperties(properties);
return mapperScannerConfigurer;
}
}
@PropertySource({
"classpath:property-brh.properties",
"classpath:property-houbank.properties",
"classpath:property-zbank.properties",
"classpath:property-sanxiang.properties"
})
@SpringBootApplication
@EnableTransactionManagement
public class RunApiApplication extends SpringBootServletInitializer {}