Spring Boot集成多数据源Oracle、Mysql、SqlServer等+Mybatis+pageHelper分页+CodeGenerator根据表自动生成服务端代码
关键代码和gitee如下:
1. pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.5</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.xymc</groupId> <artifactId>webmgr</artifactId> <version>0.0.1-SNAPSHOT</version> <name>webmgr</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.10</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency> <!-- aop依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <!-- mybatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.47</version> <scope>runtime</scope> </dependency> <!-- druid监控依赖 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.9</version> </dependency> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.3</version> </dependency> <!--SqlServer数据库驱动--> <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>sqljdbc4</artifactId> <version>4.0</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> </dependency> <!--Mybatis plus Begin--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-extension</artifactId> <version>3.1.0</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>3.1.0</version> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> <version>2.1</version> </dependency> <!--Mybatis plus End--> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.41</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.4</version> </dependency> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.7.8</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
2. application.yml、application-dev.yml、application-test.yml、application-prod.yml配置文件
2.1 application.yml。主要是配置统一的配置信息,比如端口号、项目路径、全局返回码、以及选择加载开发测试生产的数据源配置文件
spring: #环境配置:dev、test、prod profiles: active: dev #端口号和项目路径 server: port: 8080 servlet: context-path: /lygserv #------------------------------------------全局返回码------------------------------------------ retCode0: 0 retCode1: 1 retCode2: 2 retCode3: 3 retCode4: 4 retCode5: 5 retCode6: 6 retCode7: 7 retCode8: 8 retCode9: 9 retCode10: 10 retCode11: 11 retCode101: 101 retCode102: 102 retCode103: 103 retCode104: 104 retCode105: 105 retCode404: 404 #------------------------------------------全局返回码释义------------------------------------------ retMsg0: 操作成功 retMsg1: 操作失败 retMsg2: 请求超时 retMsg3: 请求错误 retMsg4: 参数不合法 retMsg5: 网络异常 retMsg6: 系统繁忙 retMsg7: 非法请求 retMsg8: 未知错误 retMsg9: 系统错误 retMsg10: Feign请求超时,进入Hystrix断路器 retMsg11: 请求过于频繁,请稍后再试 retMsg101: 账号不存在 retMsg102: 密码不正确 retMsg103: 此账号无登录权限 retMsg104: 账号关联信息不存在 retMsg105: 账号关联信息已存在 retMsg404: 请求地址不存在
2.2 application_dev.yml。开发环境的数据源配置文件(application_test.yml和application_prod.yml一样,只需要调整具体的数据库连接信息即可)
spring: datasource: #mysql数据源 db1: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://ip:3306/test?zeroDateTimeBehavior=convertToNull username: admin password: 123456 #oracle数据源 db2: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: oracle.jdbc.driver.OracleDriver url: jdbc:oracle:thin:@ip:1521/test username: admin password: 123456 #sqlserver数据源 db3: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver url: jdbc:sqlserver://ip:1433;DatabaseName=test username: admin password: 123456 #sql打印 logging: level: com.xymc.webmgr.dao.db1: debug com.xymc.webmgr.dao.db2: debug com.xymc.webmgr.dao.db3: debug
3. 数据源相关配置
3.1 MyBatisConfigdb1.java:mysql数据源配置信息,包括数据源信息读取,dao和mapper文件包路径的扫描配置。(注意:此配置文件中有@Primary注解,为主数据源,只需要在一个配置文件中配置,其他配置文件中不需要配置此注解)
package com.xymc.webmgr.config.datasource; import com.alibaba.druid.pool.DruidDataSource; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import javax.sql.DataSource; /** * <p>mysql数据源<p> * * @Version : 1.0 * @Author : lihao * @Description :mysql的数据源 * 这里我们定义的数据源要扫描mysql对应的mapper.java包和mapper.xml目录 * @Date : 2021/10/27 14:38 **/ @Configuration @MapperScan(basePackages = MyBatisConfigdb1.PACKAGE,sqlSessionFactoryRef = "db1SqlSessionFactory") public class MyBatisConfigdb1 { // 精确到 db1 目录,以便跟其他数据源隔离 static final String PACKAGE = "com.xymc.webmgr.dao.db1"; static final String MAPPER_LOCATION = "classpath:mappers/db1/*.xml"; @Value("${spring.datasource.db1.url}") private String url; @Value("${spring.datasource.db1.username}") private String user; @Value("${spring.datasource.db1.password}") private String password; // @Value("${spring.datasource.db1.driverClassName}") // private String driverClass; @Bean(name = "db1DataSource") @Primary public DataSource db1DataSource() { DruidDataSource dataSource = new DruidDataSource(); // dataSource.setDriverClassName(driverClass); dataSource.setUrl(url); dataSource.setUsername(user); dataSource.setPassword(password); return dataSource; } @Bean(name = "db1TransactionManager") @Primary public DataSourceTransactionManager db1TransactionManager() { return new DataSourceTransactionManager(db1DataSource()); } @Bean(name = "db1SqlSessionFactory") @Primary public SqlSessionFactory db1SqlSessionFactory(@Qualifier("db1DataSource") DataSource db1DataSource) throws Exception { final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(db1DataSource); sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver() .getResources(MyBatisConfigdb1.MAPPER_LOCATION)); return sessionFactory.getObject(); } }
3.2 MyBatisConfigdb2.java:oracle数据源配置信息,包括数据源信息读取,dao和mapper文件包路径的扫描配置。
package com.xymc.webmgr.config.datasource; import com.alibaba.druid.pool.DruidDataSource; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import javax.sql.DataSource; /** * <p>Oracle数据源><p> * * @Version : 1.0 * @Author : lihao * @Description :Oracle的数据源 * 这里我们定义的数据源要扫描oracle对应的mapper.java包和mapper.xml目录 * @Date : 2021/10/27 14:39 **/ @Configuration @MapperScan(basePackages = MyBatisConfigdb2.PACKAGE,sqlSessionFactoryRef = "db2SqlSessionFactory") public class MyBatisConfigdb2 { // 精确到 db2 目录,以便跟其他数据源隔离 static final String PACKAGE = "com.xymc.webmgr.dao.db2"; static final String MAPPER_LOCATION = "classpath:mappers/db2/*.xml"; @Value("${spring.datasource.db2.url}") private String url; @Value("${spring.datasource.db2.username}") private String user; @Value("${spring.datasource.db2.password}") private String password; @Value("${spring.datasource.db2.driver-class-name}") private String driverClass; @Bean(name = "db2DataSource") public DataSource clusterDataSource() { DruidDataSource dataSource = new DruidDataSource(); dataSource.setDriverClassName(driverClass); dataSource.setUrl(url); dataSource.setUsername(user); dataSource.setPassword(password); return dataSource; } @Bean(name = "db2TransactionManager") public DataSourceTransactionManager clusterTransactionManager() { return new DataSourceTransactionManager(clusterDataSource()); } @Bean(name = "db2SqlSessionFactory") public SqlSessionFactory clusterSqlSessionFactory(@Qualifier("db2DataSource") DataSource clusterDataSource) throws Exception { final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(clusterDataSource); sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver() .getResources(MyBatisConfigdb2.MAPPER_LOCATION)); return sessionFactory.getObject(); } }
3.3 MyBatisConfigdb3.java:Sqlserver数据源配置信息,包括数据源信息读取,dao和mapper文件包路径的扫描配置。
package com.xymc.webmgr.config.datasource; import com.alibaba.druid.pool.DruidDataSource; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import javax.sql.DataSource; /** * <p>Oracle数据源><p> * * @Version : 1.0 * @Author : lihao * @Description :SqlServer的数据源 * 这里我们定义的数据源要扫描SqlServer对应的mapper.java包和mapper.xml目录 * @Date : 2021/10/27 14:39 **/ @Configuration @MapperScan(basePackages = MyBatisConfigdb3.PACKAGE,sqlSessionFactoryRef = "db3SqlSessionFactory") public class MyBatisConfigdb3 { // 精确到 db3 目录,以便跟其他数据源隔离 static final String PACKAGE = "com.xymc.webmgr.dao.db3"; static final String MAPPER_LOCATION = "classpath:mappers/db3/*.xml"; @Value("${spring.datasource.db3.url}") private String url; @Value("${spring.datasource.db3.username}") private String user; @Value("${spring.datasource.db3.password}") private String password; @Value("${spring.datasource.db3.driver-class-name}") private String driverClass; @Bean(name = "db3DataSource") public DataSource clusterDataSource() { DruidDataSource dataSource = new DruidDataSource(); dataSource.setDriverClassName(driverClass); dataSource.setUrl(url); dataSource.setUsername(user); dataSource.setPassword(password); return dataSource; } @Bean(name = "db3TransactionManager") public DataSourceTransactionManager clusterTransactionManager() { return new DataSourceTransactionManager(clusterDataSource()); } @Bean(name = "db3SqlSessionFactory") public SqlSessionFactory clusterSqlSessionFactory(@Qualifier("db3DataSource") DataSource clusterDataSource) throws Exception { final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(clusterDataSource); sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver() .getResources(MyBatisConfigdb3.MAPPER_LOCATION)); return sessionFactory.getObject(); } }
4. 项目工程目录结构
其中,config.datasource中的三个文件就是三个数据库的具体的配置;dao和mappers中的db1、db2、db3、分别对应mysql、oracle、sqlserver数据源的dao.java和mapper.xml。这样不同的数据源对应不同的dao和mapper,扫描不同的位置,既方便开发,也便于后期的查找维护。
5. CodeGenerator根据表自动生成服务端代码。
其中mybatisPlusGenerator中的CodeGenerator.java是生成代码的配置及main方法,GeneratorConstants.java是数据库的连接信息和生成的文件位置信息;
其中资源文件夹resources中的templates中的则是生成文件代码模板,可以根据需求自定义调整。
5.1 CodeGenerator.java 代码生成工具类,运行这里的main方法即可自动生成代码。
package com.xymc.webmgr.utils.mybatisPlusGenerator; import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.generator.AutoGenerator; import com.baomidou.mybatisplus.generator.config.*; import com.baomidou.mybatisplus.generator.config.rules.DateType; import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; import org.apache.commons.lang3.StringUtils; /** * @ClassName: CodeGeneratorPackageConfig * @Description: 代码生成工具类。运行这里的main方法即可自动生成代码 * @Author li_hao * @Date 2020-04-09 16:32 */ public class CodeGenerator { /** * MySQL/Oracle 生成 */ public static void main(String[] args) { // 自定义需要填充的字段 // List<TableFill> tableFillList = new ArrayList<>(); // tableFillList.add(new TableFill("ASDD_SS", FieldFill.INSERT_UPDATE)); AutoGenerator mpg = new AutoGenerator(); // 选择 freemarker 引擎,默认 Veloctiy // mpg.setTemplateEngine(new FreemarkerTemplateEngine()); // 全局配置 GlobalConfig gc = new GlobalConfig(); gc.setOutputDir(GeneratorConstants.PROJECT_DIR + GeneratorConstants.JAVA_DIR); // gc.setFileOverride(true);// 是否覆盖文件 gc.setFileOverride(false);// 是否覆盖文件 gc.setActiveRecord(true);// 不需要ActiveRecord特性的请改为false gc.setEnableCache(false);// XML 二级缓存 gc.setBaseResultMap(true);// XML ResultMap gc.setBaseColumnList(true);// XML columList //gc.setKotlin(true);//是否生成 kotlin 代码 gc.setAuthor(GeneratorConstants.AUTOR); //时间类型 gc.setDateType(DateType.ONLY_DATE); // 自定义文件命名,注意 %s 会自动填充表实体属性! gc.setMapperName("%sDao"); gc.setXmlName("%sMapper"); gc.setServiceName("%sService"); gc.setServiceImplName("%sServiceImpl"); gc.setControllerName("%sController"); mpg.setGlobalConfig(gc); // 数据源配置 DataSourceConfig dsc = new DataSourceConfig(); dsc.setDbType(DbType.MYSQL); // dsc.setDbType(DbType.ORACLE); /*dsc.setTypeConvert(new MySqlTypeConvert(){ // 自定义数据库表字段类型转换【可选】 public DbColumnType processTypeConvert(String fieldType) { System.out.println("转换类型:" + fieldType); // 注意!!processTypeConvert 存在默认类型转换,如果不是你要的效果请自定义返回、非如下直接返回。 return super.processTypeConvert(fieldType); } });*/ dsc.setDriverName(GeneratorConstants.DB_DRIVER); dsc.setUrl(GeneratorConstants.DB_URL); dsc.setUsername(GeneratorConstants.DB_USER_NAME); dsc.setPassword(GeneratorConstants.DB_PASSWORD); mpg.setDataSource(dsc); // 策略配置 StrategyConfig strategy = new StrategyConfig(); // 全局大写命名 ORACLE 注意 // strategy.setCapitalMode(true); // 此处可以修改为您的表前缀 //strategy.setTablePrefix(new String[] { "tlog_", "tsys_" }); // 表名生成策略 strategy.setNaming(NamingStrategy.underline_to_camel); // 需要生成的表,注释掉生成全部表 // String tables = ""; // StringUtils.split(tables); strategy.setInclude(StringUtils.split(GeneratorConstants.TABLES, ",")); // strategy.setExclude(new String[]{"test"}); // 排除生成的表 // 自定义实体父类 // strategy.setSuperEntityClass("com.baomidou.demo.TestEntity"); // 自定义实体,公共字段 // strategy.setSuperEntityColumns(new String[] { "test_id", "age" }); // 自定义 mapper 父类 // strategy.setSuperMapperClass("com.baomidou.demo.TestMapper"); // 自定义 service 父类 // strategy.setSuperServiceClass("com.baomidou.demo.TestService"); // 自定义 service 实现类父类 // strategy.setSuperServiceImplClass("com.baomidou.demo.TestServiceImpl"); // 自定义 controller 父类 // strategy.setSuperControllerClass("com.baomidou.demo.TestController"); // 【实体】是否生成字段常量(默认 false) // public static final String ID = "test_id"; //strategy.setEntityColumnConstant(true); // 【实体】是否为构建者模型(默认 false) // public User setName(String name) {this.name = name; return this;} //strategy.setEntityBuilderModel(true); // 【实体】是否为lombok模型(默认 false)<a href="https://projectlombok.org/">document</a> strategy.setEntityLombokModel(true); // strategy.setTableFillList(tableFillList); mpg.setStrategy(strategy); // 包配置 PackageConfig pc = new PackageConfig(); pc.setModuleName(GeneratorConstants.MODULE); pc.setParent(GeneratorConstants.PARENT_PACKAGE); pc.setController(GeneratorConstants.CHILD_PACKAGE_CONTROLLER); pc.setEntity(GeneratorConstants.CHILD_PACKAGE_ENTITY); pc.setMapper(GeneratorConstants.CHILD_PACKAGE_DAO); pc.setXml(GeneratorConstants.CHILD_PACKAGE_MAPPERXML); pc.setService(GeneratorConstants.CHILD_PACKAGE_SERVICE); pc.setServiceImpl(GeneratorConstants.CHILD_PACKAGE_SERVICEIMPL); mpg.setPackageInfo(pc); // 注入自定义配置,可以在 VM 中使用 cfg.abc 【可无】 ${cfg.abc} // InjectionConfig cfg = new InjectionConfig() { // @Override // public void initMap() { // Map<String, Object> map = new HashMap<String, Object>(); // map.put("abc", this.getConfig().getGlobalConfig().getAuthor() + "-mp"); // this.setMap(map); // } // }; // 自定义 xxListIndex.html 生成 // List<FileOutConfig> focList = new ArrayList<FileOutConfig>(); // focList.add(new FileOutConfig("/templates/list.html.vm") { // @Override // public String outputFile(TableInfo tableInfo) { // // 自定义输入文件名称 // return "F:/idea-maven/maven/src/main/resources/static/" + tableInfo.getEntityName() + "ListIndex.html"; // } // }); // cfg.setFileOutConfigList(focList); // mpg.setCfg(cfg); // 关闭默认 xml 生成,调整生成 至 根目录 /*TemplateConfig tc = new TemplateConfig(); tc.setXml(null); mpg.setTemplate(tc);*/ // 自定义模板配置,可以 copy 源码 mybatis-plus/src/main/resources/templates 下面内容修改, // 放置自己项目的 src/main/resources/templates 目录下, 默认名称一下可以不配置,也可以自定义模板名称 TemplateConfig tc = new TemplateConfig(); // tc.setController("/templates/Controller.java.vm"); // tc.setService("/templates/Service.java.vm"); // tc.setServiceImpl("/templates/ServiceImpl.java.vm"); // tc.setEntity("/templates/Entity.java.vm"); // tc.setMapper("/templates/Mapper.java.vm"); // tc.setXml("/templates/Mapper.xml.vm"); // 如上任何一个模块如果设置 空 OR Null 将不生成该模块。 mpg.setTemplate(tc); // 执行生成 mpg.execute(); // 打印注入设置【可无】 // System.err.println(mpg.getCfg().getMap().get("abc")); } }
5.2 GeneratorConstants.java 代码生成数据源配置类,数据库的连接信息和生成的文件位置信息。
package com.xymc.webmgr.utils.mybatisPlusGenerator; /** * @ClassName: GeneratorConfig * @Description: 代码生成配置类 * @Author li_hao * @Date 2020-04-09 16:04 */ public class GeneratorConstants { /** * 项目路径 **/ public static final String PROJECT_DIR = "D:/李浩/工作/贺姐2/项目工程/xymcserv"; /** * java类目录 **/ public static final String JAVA_DIR = "/src/main/java"; /** * 作者 **/ public static final String AUTOR = "li_hao"; /** * 数据库配置 **/ // public static final String DB_DRIVER = "oracle.jdbc.OracleDriver"; // public static final String DB_URL = "jdbc:oracle:thin:@ip:1521/test"; // public static final String DB_USER_NAME = "admin"; // public static final String DB_PASSWORD = "123456"; // public static final String DB_DRIVER = "com.mysql.jdbc.Driver"; public static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver"; public static final String DB_URL = "jdbc:mysql://ip:3306/test"; public static final String DB_USER_NAME = "admin"; public static final String DB_PASSWORD = "123456"; /** * 指定生成的表 , 用 ","分割 **/ public static final String TABLES = "t_user"; /** * 模块名称 **/ public static final String MODULE = "webmgr"; /** * 父级包名 **/ public static final String PARENT_PACKAGE = "com.xymc"; /** * 子级controller前端控制器所在包名。释义:生成的controller前端控制器文件所在文件夹的名字 **/ public static final String CHILD_PACKAGE_CONTROLLER = "controller"; /** * 子级entity实体类所在包名。释义:生成的entity实体类文件所在文件夹的名字 **/ public static final String CHILD_PACKAGE_ENTITY = "entity"; /** * 子级dao/Mapper接口类所在包名。释义:生成的dao/Mapper接口类文件所在文件夹的名字 **/ public static final String CHILD_PACKAGE_DAO = "dao.db1"; /** * 子级Mapper.xml文件所在包名。释义:生成的Mapper.xml文件所在文件夹的名字 **/ public static final String CHILD_PACKAGE_MAPPERXML = "dao.db1"; /** * 子级service服务接口文件所在包名。释义:生成的service服务接口文件所在文件夹的名字 **/ public static final String CHILD_PACKAGE_SERVICE = "service"; /** * 子级service.impl服务接口实现类文件所在包名。释义:生成的service.impl服务接口实现类文件所在文件夹的名字 **/ public static final String CHILD_PACKAGE_SERVICEIMPL = "service.impl"; }
注意:此工程为同时配置mysql、oracle、sqlserver三个数据源,如果不需要同时配置三个,请把不需要的那个数据源的datasources中的配置注释掉即可,否则在项目启动的时候,程序会初始化连接到数据库,发现连接失败时,会提示一个连接时报的错误。
当然,如果有很多个数据源也没关系,比如5个mysql、3个oracle、2个sqlserver也是一样的,多在ymldatasources和中配置几个数据源的信息即可。
工程代码gitee地址:https://gitee.com/older/springbootDatas