StrategyConfig.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /**
  2. * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  3. * <p>
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. * <p>
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. * <p>
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.baomidou.mybatisplus.generator.config;
  17. import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
  18. import com.baomidou.mybatisplus.toolkit.StringUtils;
  19. /**
  20. * <p>
  21. * 策略配置项
  22. * </p>
  23. *
  24. * @author YangHu, tangguo, hubin
  25. * @since 2016/8/30
  26. */
  27. public class StrategyConfig {
  28. /**
  29. * 表名、字段名、是否使用下划线命名(默认 false)
  30. */
  31. public static boolean DB_COLUMN_UNDERLINE = false;
  32. /**
  33. * 是否大写命名
  34. */
  35. private boolean isCapitalMode = false;
  36. /**
  37. * 数据库表映射到实体的命名策略
  38. */
  39. private NamingStrategy naming = NamingStrategy.nochange;
  40. /**
  41. * 表前缀
  42. */
  43. private String[] tablePrefix;
  44. /**
  45. * 自定义继承的Entity类全称,带包名
  46. */
  47. private String superEntityClass;
  48. /**
  49. * 自定义基础的Entity类,公共字段
  50. */
  51. private String[] superEntityColumns;
  52. /**
  53. * 自定义继承的Mapper类全称,带包名
  54. */
  55. private String superMapperClass = ConstVal.SUPERD_MAPPER_CLASS;
  56. /**
  57. * 自定义继承的Service类全称,带包名
  58. */
  59. private String superServiceClass = ConstVal.SUPERD_SERVICE_CLASS;
  60. /**
  61. * 自定义继承的ServiceImpl类全称,带包名
  62. */
  63. private String superServiceImplClass = ConstVal.SUPERD_SERVICEIMPL_CLASS;
  64. /**
  65. * 自定义继承的Controller类全称,带包名
  66. */
  67. private String superControllerClass;
  68. /*
  69. * 需要包含的表名(与exclude二选一配置)
  70. */
  71. private String[] include = null;
  72. /**
  73. * 需要排除的表名
  74. */
  75. private String[] exclude = null;
  76. /**
  77. * 【实体】是否生成字段常量(默认 false)<br>
  78. * -----------------------------------<br>
  79. * public static final String ID = "test_id";
  80. */
  81. private boolean entityColumnConstant = false;
  82. /**
  83. * 【实体】是否为构建者模型(默认 false)<br>
  84. * -----------------------------------<br>
  85. * public User setName(String name) { this.name = name; return this; }
  86. */
  87. private boolean entityBuilderModel = false;
  88. /**
  89. * 【实体】是否为lombok模型(默认 false)<br>
  90. * <a href="https://projectlombok.org/">document</a>
  91. */
  92. private boolean entityLombokModel = false;
  93. /**
  94. * Boolean类型字段是否移除is前缀(默认 false)<br>
  95. * 比如 : 数据库字段名称 : 'is_xxx',类型为 : tinyint. 在映射实体的时候则会去掉is,在实体类中映射最终结果为 xxx
  96. */
  97. private boolean entityBooleanColumnRemoveIsPrefix = false;
  98. /**
  99. * 生成 <code>@RestController</code> 控制器
  100. * <pre>
  101. * <code>@Controller</code> -> <code>@RestController</code>
  102. * </pre>
  103. */
  104. private boolean restControllerStyle = false;
  105. /**
  106. * 驼峰转连字符
  107. * <pre>
  108. * <code>@RequestMapping("/managerUserActionHistory")</code> -> <code>@RequestMapping("/manager-user-action-history")</code>
  109. * </pre>
  110. */
  111. private boolean controllerMappingHyphenStyle = false;
  112. public void setDbColumnUnderline(boolean dbColumnUnderline) {
  113. DB_COLUMN_UNDERLINE = dbColumnUnderline;
  114. }
  115. /**
  116. * <p>
  117. * 大写命名、字段符合大写字母数字下划线命名
  118. * </p>
  119. *
  120. * @param word 待判断字符串
  121. * @return
  122. */
  123. public boolean isCapitalModeNaming(String word) {
  124. return isCapitalMode && StringUtils.isCapitalMode(word);
  125. }
  126. /**
  127. * <p>
  128. * 表名称包含指定前缀
  129. * </p>
  130. *
  131. * @param tableName 表名称
  132. * @return
  133. */
  134. public boolean containsTablePrefix(String tableName) {
  135. if (null != tableName) {
  136. String[] tps = getTablePrefix();
  137. if (null != tps) {
  138. for (String tp : tps) {
  139. if (tableName.contains(tp)) {
  140. return true;
  141. }
  142. }
  143. }
  144. }
  145. return false;
  146. }
  147. public boolean isCapitalMode() {
  148. return isCapitalMode;
  149. }
  150. public void setCapitalMode(boolean isCapitalMode) {
  151. this.isCapitalMode = isCapitalMode;
  152. }
  153. public NamingStrategy getNaming() {
  154. return naming;
  155. }
  156. public void setNaming(NamingStrategy naming) {
  157. this.naming = naming;
  158. }
  159. public String[] getTablePrefix() {
  160. return tablePrefix;
  161. }
  162. public void setTablePrefix(String[] tablePrefix) {
  163. this.tablePrefix = tablePrefix;
  164. }
  165. public String getSuperEntityClass() {
  166. return superEntityClass;
  167. }
  168. public void setSuperEntityClass(String superEntityClass) {
  169. this.superEntityClass = superEntityClass;
  170. }
  171. public boolean includeSuperEntityColumns(String fieldName) {
  172. if (null != superEntityColumns) {
  173. for (String column : superEntityColumns) {
  174. if (column.contains(fieldName)) {
  175. return true;
  176. }
  177. }
  178. }
  179. return false;
  180. }
  181. public String[] getSuperEntityColumns() {
  182. return superEntityColumns;
  183. }
  184. public void setSuperEntityColumns(String[] superEntityColumns) {
  185. this.superEntityColumns = superEntityColumns;
  186. }
  187. public String getSuperMapperClass() {
  188. return superMapperClass;
  189. }
  190. public void setSuperMapperClass(String superMapperClass) {
  191. this.superMapperClass = superMapperClass;
  192. }
  193. public String getSuperServiceClass() {
  194. return superServiceClass;
  195. }
  196. public void setSuperServiceClass(String superServiceClass) {
  197. this.superServiceClass = superServiceClass;
  198. }
  199. public String getSuperServiceImplClass() {
  200. return superServiceImplClass;
  201. }
  202. public void setSuperServiceImplClass(String superServiceImplClass) {
  203. this.superServiceImplClass = superServiceImplClass;
  204. }
  205. public String getSuperControllerClass() {
  206. return superControllerClass;
  207. }
  208. public void setSuperControllerClass(String superControllerClass) {
  209. this.superControllerClass = superControllerClass;
  210. }
  211. public String[] getInclude() {
  212. return include;
  213. }
  214. public void setInclude(String[] include) {
  215. this.include = include;
  216. }
  217. public String[] getExclude() {
  218. return exclude;
  219. }
  220. public void setExclude(String[] exclude) {
  221. this.exclude = exclude;
  222. }
  223. public boolean isEntityColumnConstant() {
  224. return entityColumnConstant;
  225. }
  226. public void setEntityColumnConstant(boolean entityColumnConstant) {
  227. this.entityColumnConstant = entityColumnConstant;
  228. }
  229. public boolean isEntityBuilderModel() {
  230. return entityBuilderModel;
  231. }
  232. public void setEntityBuilderModel(boolean entityBuilderModel) {
  233. this.entityBuilderModel = entityBuilderModel;
  234. }
  235. public boolean isEntityLombokModel() {
  236. return entityLombokModel;
  237. }
  238. public void setEntityLombokModel(boolean entityLombokModel) {
  239. this.entityLombokModel = entityLombokModel;
  240. }
  241. public boolean isEntityBooleanColumnRemoveIsPrefix() {
  242. return entityBooleanColumnRemoveIsPrefix;
  243. }
  244. public void setEntityBooleanColumnRemoveIsPrefix(boolean entityBooleanColumnRemoveIsPrefix) {
  245. this.entityBooleanColumnRemoveIsPrefix = entityBooleanColumnRemoveIsPrefix;
  246. }
  247. public boolean isRestControllerStyle() {
  248. return restControllerStyle;
  249. }
  250. public void setRestControllerStyle(boolean restControllerStyle) {
  251. this.restControllerStyle = restControllerStyle;
  252. }
  253. public boolean isControllerMappingHyphenStyle() {
  254. return controllerMappingHyphenStyle;
  255. }
  256. public void setControllerMappingHyphenStyle(boolean controllerMappingHyphenStyle) {
  257. this.controllerMappingHyphenStyle = controllerMappingHyphenStyle;
  258. }
  259. }