@Configuration
public class MybatisConfig {
public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception {
SqlSessionFactoryBean factroy =new SqlSessionFactoryBean();
factory.setDataSource(dataSource);
VFS.addImplClass(SpringBootVFS.class) ;
factory.setTypeAliasesPackage(com.cn.test.bean); //实体包路径
ResourcePatternResolver resolver =new PathMatchingResourcePatternResolver();
factory.setMapperLoccations(resolver.getResources("classPath:mapper/*.xml"));
//配置分页插件
PageHelper pageHelper =new PageHelper();
Properties properties =new Properties();
properties.setProperty("pageSizeZero","true"); //分页尺寸为0时候查询所有记录不再执行分页
properties.setProperty("reasonable","true"); //页码<=查询第一页 ,页码>=总页数查询最后一页
properties.setProperty("supportMethodsArguments","true"); // 支持通过mapper接口参数传递分页参数
pageHelper.setProperties(properties);
//添加插件
factory.setPlugings(new Interceptor[ ]{pageHelper});
try{
//开启驼峰命名转换
factory.getObject.getConfiguration.setMapUnderscoreToCameCase(true);
return factory.getObject();
}catch(Exception e){
throw new RuntimeException(e);
}
}
public MapperScannerConfigurer mapperScannerConfigurer(){
MapperScannerConfigurer mapperScannerConfigurer =new MapperScannerConfigurer();
mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactoryBean");
mapperScannerConfigurer.setBasePackage(com.cn.test.web.dao.mapper); //存放mapper接口的包路径
//配置通用mapper
Properties properties =new Properties();
properties.setProerty("mappers",com.cin.test.dao.base.mapper); //mapper插件基础接口的全限定明 此包下的Mapper
properties.setProperty("notEmpty","false");
properties.setProperty("IDENTITY","MYSQL");
mapperScannerConfigurer.setProperties(properties);
return mapperScannerConfigurer;
}
}