MappingGeneratorOracle.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //package com.fdkankan.modeldemo.generator;
  2. //
  3. //import com.baomidou.mybatisplus.annotation.DbType;
  4. //import com.baomidou.mybatisplus.annotation.IdType;
  5. //import com.baomidou.mybatisplus.generator.AutoGenerator;
  6. //import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
  7. //import com.baomidou.mybatisplus.generator.config.GlobalConfig;
  8. //import com.baomidou.mybatisplus.generator.config.PackageConfig;
  9. //import com.baomidou.mybatisplus.generator.config.StrategyConfig;
  10. //import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
  11. //import com.baomidou.mybatisplus.generator.config.rules.DateType;
  12. //import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
  13. //import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
  14. //
  15. ///**
  16. // * 代码生成器
  17. // *
  18. // * <p>
  19. // * 根据数据库中的表生成:数据库表映射对象、Mapper 接口、Mapper XML 文件(含基础的 ResultMap 和字段代码片段)、 Service
  20. // * 接口、Service 接口实现累、基础的 Controller 类。
  21. // * </p>
  22. // * <p>
  23. // * 如果数据库设计符合规范,并且代码没有特殊要求。设置好表名前缀(无则忽略)、表字段前缀(无则忽略)后, 直接修改输出的路径、JDBC
  24. // * Url、数据库的账户和密码即可直接生成代码。
  25. // * </p>
  26. // * <p>
  27. // * 生成后将 Mapper 中的 xml 包中的 XML 文件移动到 resource 下即可,XML 存放文件夹名为 Mapper
  28. // * 接口包名(全包名)的同名文件夹<br/>
  29. // * 如 Mapper 接口包名为:com.example.mapper,那么在 resource 下新建同名文件夹:com.example.mapper,将
  30. // * xml 文件移动到该文件夹下即可。
  31. // * </p>
  32. // *
  33. // * @author wayne
  34. // * @since 2020-01-08 23:00
  35. // */
  36. //public class MappingGeneratorOracle {
  37. //
  38. // /**
  39. // * 生成代码输出路径,<strong>路径必须是绝对路径,不需要包含包名</strong>
  40. // */
  41. // private static final String OUTPUT_DIR = ".\\src\\main\\java\\com\\fdkankan\\modeldemo\\generator";
  42. // /**
  43. // * 生成代码输出的包名
  44. // * <p>
  45. // * 总包名,后续生成的 Mapper,Service 等将在该包下生成子包
  46. // * </p>
  47. // */
  48. // private static final String PACKAGE = "com.fdkankan.modeldemo";
  49. // /**
  50. // * JDBC URL 说明: url地址前需要加上@,否则会报错
  51. // */
  52. //
  53. // private static final String JDBC_URL = "jdbc:oracle:thin:@//10.180.41.39:1521/resdb";
  54. // /**
  55. // * 数据库账户
  56. // */
  57. // private static final String DB_USERNAME = "RES_VR";
  58. // /**
  59. // * 数据库账户密码
  60. // */
  61. // private static final String DB_PASSWORD = "IDCqawsed@123.";
  62. //
  63. // /**
  64. // * 执行即可生成代码 需要添加 freemarker 依赖 <dependency> <groupId>org.freemarker</groupId>
  65. // * <artifactId>freemarker</artifactId> <version>2.3.29</version> </dependency>
  66. // */
  67. // // 不要在src/main/java里面使用main方法,否则springboot项目某人为main方法的类就是启动类
  68. //// public static void main(String[] args) {
  69. //// autoGenerator().execute();
  70. //// }
  71. //
  72. // public static AutoGenerator autoGenerator() {
  73. // AutoGenerator autoGenerator = new AutoGenerator();
  74. // autoGenerator.setGlobalConfig(globalConfig());
  75. // autoGenerator.setDataSource(oracleDataSourceConfig());
  76. // autoGenerator.setStrategy(strategyConfig());
  77. // autoGenerator.setPackageInfo(packageConfig());
  78. // autoGenerator.setTemplateEngine(new FreemarkerTemplateEngine());
  79. // return autoGenerator;
  80. // }
  81. //
  82. // public static void main(String[] args) {
  83. // autoGenerator().execute();
  84. // }
  85. //
  86. // /**
  87. // * 全局配置
  88. // *
  89. // * @return {@link GlobalConfig}
  90. // */
  91. // private static GlobalConfig globalConfig() {
  92. // GlobalConfig globalConfig = new GlobalConfig();
  93. // globalConfig.setAuthor("dsx");
  94. // // 设置代码输出位置,需要绝对路径
  95. // globalConfig.setOutputDir(OUTPUT_DIR);
  96. // // 覆盖已有的代码
  97. // globalConfig.setFileOverride(false);
  98. // // 基本表的 ResultMap
  99. // globalConfig.setBaseResultMap(true);
  100. // // 基本表字段片段
  101. // globalConfig.setBaseColumnList(true);
  102. // // 开启基于 Model 操作数据库
  103. // globalConfig.setActiveRecord(true);
  104. // // 设置 ID 类型
  105. // globalConfig.setIdType(IdType.AUTO);
  106. // globalConfig.setDateType(DateType.ONLY_DATE);
  107. //// // 生成基本 Swagger2 文档
  108. //// globalConfig.setSwagger2(true);
  109. // // 开启二级缓存
  110. //// globalConfig.setEnableCache(true);
  111. // // 设置生成的对象名称规则,%s 表示当前的 Entity
  112. // // 数据库表映射对象名称规则
  113. // globalConfig.setEntityName("%s");
  114. // // 也可以使用下面这种就是末尾会以DO结尾
  115. //// globalConfig.setEntityName("%sDO");
  116. // // Mapper 接口名称规则
  117. // globalConfig.setMapperName("%sMapper");
  118. // // Mapper XML 文件名称规则
  119. // globalConfig.setXmlName("%sMapper");
  120. // // Controller 生成规则
  121. // globalConfig.setControllerName("%sController");
  122. // // Service 接口生成名称规则
  123. // globalConfig.setServiceName("%sService");
  124. // // Service 实现类生成名称规则
  125. // globalConfig.setServiceImplName("%sServiceImpl");
  126. // return globalConfig;
  127. // }
  128. //
  129. // /**
  130. // * 生成策略配置
  131. // *
  132. // * @return StrategyConfig
  133. // */
  134. // private static StrategyConfig strategyConfig() {
  135. // StrategyConfig strategyConfig = new StrategyConfig();
  136. // strategyConfig.setCapitalMode(false);
  137. // strategyConfig.setEntityLombokModel(true);
  138. // strategyConfig.setRestControllerStyle(true);
  139. // strategyConfig.setNaming(NamingStrategy.underline_to_camel);
  140. // strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);
  141. // // TODO 填写表前缀、表字段前缀,生成代码时去除字段前缀
  142. // strategyConfig.setTablePrefix("t_");
  143. // strategyConfig.setFieldPrefix("a_", "c_", "e_", "f_", "p_", "r_", "t_", "tf_");
  144. // strategyConfig.setInclude("T_FULLPHOTO_FILEINDEX");
  145. // return strategyConfig;
  146. // }
  147. //
  148. // /**
  149. // * MySQL 数据源配置
  150. // *
  151. // * @return DataSourceConfig
  152. // */
  153. // private static DataSourceConfig oracleDataSourceConfig() {
  154. // DataSourceConfig dataSourceConfig = new DataSourceConfig();
  155. // dataSourceConfig.setDbType(DbType.ORACLE);
  156. // dataSourceConfig.setTypeConvert(new MySqlTypeConvert());
  157. // dataSourceConfig.setDriverName("oracle.jdbc.driver.OracleDriver");
  158. // dataSourceConfig.setUrl(JDBC_URL);
  159. // dataSourceConfig.setUsername(DB_USERNAME);
  160. // dataSourceConfig.setPassword(DB_PASSWORD);
  161. // return dataSourceConfig;
  162. // }
  163. //
  164. // /**
  165. // * 包相关配置信息
  166. // * <p>
  167. // * 配置生成代码的包信息,如生成的 Mapper 包,Service 包等
  168. // * </p>
  169. // */
  170. // private static PackageConfig packageConfig() {
  171. // PackageConfig packageConfig = new PackageConfig();
  172. // // 设置父包
  173. // packageConfig.setParent(PACKAGE);
  174. // // TODO 设置生成代码的包
  175. // // Controller 包
  176. // packageConfig.setController("controller");
  177. // // 数据库表映射对象包
  178. // packageConfig.setEntity("entity");
  179. // // Mapper 接口包,含 XML 文件
  180. // packageConfig.setMapper("mapper");
  181. // // Service 接口包
  182. // packageConfig.setService("service");
  183. // // Service 接口实现类包
  184. // packageConfig.setServiceImpl("service.impl");
  185. // return packageConfig;
  186. // }
  187. //}
  188. //