├── .gitignore
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── TODO.md
├── _config.yml
├── assets
└── 1559619424122.jpg
├── pom.xml
└── src
└── main
├── java
└── com
│ └── github
│ └── zhuyizhuo
│ └── generator
│ ├── annotation
│ ├── CoventionClass.java
│ ├── NotNull.java
│ ├── Nullable.java
│ ├── Resource.java
│ └── Value.java
│ ├── constants
│ ├── ConfigConstants.java
│ ├── LinkConstants.java
│ └── TemplateConstants.java
│ ├── enums
│ ├── DbTypeEnums.java
│ ├── ErrorTypeEnums.java
│ ├── FileTypeEnums.java
│ ├── LogLevelEnums.java
│ ├── MethodEnums.java
│ ├── ModuleTypeEnums.java
│ └── TemplateTypeEnums.java
│ ├── exception
│ └── GeneratorException.java
│ ├── mybatis
│ ├── convention
│ │ ├── ClassCommentInfo.java
│ │ └── FileOutPathInfo.java
│ ├── database
│ │ ├── entity
│ │ │ ├── ColumnInfo.java
│ │ │ ├── DataBaseInfo.java
│ │ │ └── DbTableInfo.java
│ │ ├── factory
│ │ │ └── DbServiceFactory.java
│ │ ├── mapper
│ │ │ ├── MysqlDataBaseMapper.java
│ │ │ └── OracleDataBaseMapper.java
│ │ └── service
│ │ │ ├── DbService.java
│ │ │ ├── abstracted
│ │ │ └── AbstractDbService.java
│ │ │ └── impl
│ │ │ ├── MysqlDbServiceImpl.java
│ │ │ └── OracleDbServiceImpl.java
│ ├── dto
│ │ ├── JavaClassDefinition.java
│ │ ├── JavaColumnInfo.java
│ │ ├── MethodDescription.java
│ │ └── MybatisXmlDefinition.java
│ ├── generator
│ │ ├── DefaultGenerator.java
│ │ ├── EmptyGenerator.java
│ │ ├── Generator.java
│ │ ├── GeneratorBuilder.java
│ │ ├── extension
│ │ │ ├── CustomizeModuleInfo.java
│ │ │ ├── FormatService.java
│ │ │ ├── JavaModuleInfo.java
│ │ │ └── LogService.java
│ │ ├── factory
│ │ │ └── GenerateServiceFactory.java
│ │ ├── service
│ │ │ ├── GenerateService.java
│ │ │ └── template
│ │ │ │ ├── TemplateGenerateService.java
│ │ │ │ └── freemarker
│ │ │ │ ├── FreemarkerGenerateService.java
│ │ │ │ └── impl
│ │ │ │ ├── MybatisPlusGenerateImpl.java
│ │ │ │ ├── MysqlGenerateImpl.java
│ │ │ │ └── OracleGenerateImpl.java
│ │ └── support
│ │ │ ├── ContextHolder.java
│ │ │ ├── MethodInfo.java
│ │ │ └── ModuleInfo.java
│ └── vo
│ │ ├── GenerateInfo.java
│ │ ├── GenerateMetaData.java
│ │ ├── ModulePathInfo.java
│ │ └── TableInfo.java
│ └── utils
│ ├── CheckUtils.java
│ ├── Freemarker.java
│ ├── GeneratorStringUtils.java
│ ├── LogUtils.java
│ ├── PathUtils.java
│ ├── PropertiesUtils.java
│ ├── SqlSessionUtils.java
│ └── TypeConversion.java
└── resources
├── freemarker
└── template
│ ├── java
│ ├── common
│ │ ├── batchInsert.ftl
│ │ ├── countByWhere.ftl
│ │ ├── deleteByPrimaryKey.ftl
│ │ ├── deleteByWhere.ftl
│ │ ├── insert.ftl
│ │ ├── model.ftl
│ │ ├── model_lombok.ftl
│ │ ├── queryByPrimaryKey.ftl
│ │ ├── queryByWhere.ftl
│ │ ├── updateByPrimaryKey.ftl
│ │ └── vo_swagger_lombok.ftl
│ ├── mybatis_plus
│ │ ├── mapper_mybatis_plus.ftl
│ │ ├── model_mybatis_plus.ftl
│ │ ├── model_mybatis_plus_lombok.ftl
│ │ ├── service_impl_mybatis_plus.ftl
│ │ ├── service_mybatis_plus.ftl
│ │ └── xml_mybatis_plus.ftl
│ ├── no_primary_key_mysql_mapper_template.ftl
│ ├── no_primary_key_oracle_mapper_template.ftl
│ ├── primary_key_mysql_mapper_template.ftl
│ └── primary_key_oracle_mapper_template.ftl
│ └── xml
│ ├── common
│ ├── common_sql_xml.ftl
│ ├── count_by_where_xml.ftl
│ ├── delete_by_primary_key_xml.ftl
│ ├── delete_by_where_xml.ftl
│ ├── insert_xml.ftl
│ ├── mysql_batch_insert_xml.ftl
│ ├── oracle_batch_insert_xml.ftl
│ ├── query_by_primary_key_xml.ftl
│ ├── query_by_where_xml.ftl
│ ├── result_map_xml.ftl
│ └── update_by_primary_key_xml.ftl
│ ├── no_primary_key_mysql_mybatis_template.ftl
│ ├── no_primary_key_oracle_mybatis_template.ftl
│ ├── primary_key_mysql_mybatis_template.ftl
│ └── primary_key_oracle_mybatis_template.ftl
├── generate-config.properties
├── generator.properties
└── mybatis
├── mappers
├── MysqlDataBaseMapper.xml
└── OracleDataBaseMapper.xml
└── mybatis-config.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows:
2 | Thumbs.db
3 | ehthumbs.db
4 | Desktop.ini
5 |
6 | # My configurations:
7 | *.svn
8 | *.settings
9 | *.project
10 | *.classpath
11 |
12 | # Compiled class file
13 | *.class
14 |
15 | # Log file
16 | *.log
17 |
18 | # BlueJ files
19 | *.ctxt
20 |
21 | # Mobile Tools for Java (J2ME)
22 | .mtj.tmp/
23 |
24 | # Package Files #
25 | *.jar
26 | *.war
27 | *.nar
28 | *.ear
29 | *.zip
30 | *.tar.gz
31 | *.rar
32 | .idea
33 | JavaAdvanced.iml
34 |
35 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
36 | hs_err_pid*
37 |
38 | .metadata
39 |
40 | * .TMP
41 | * .bak的
42 | * .SWP
43 | local.properties
44 | .loadpath
45 | .recommenders
46 |
47 |
48 | #STS(Spring工具套件)
49 | .springBeans
50 | /target
51 | *.iml
52 | /.idea
53 | .DS_Store
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | sudo: false # faster builds
3 |
4 | jdk:
5 | - oraclejdk12
6 | - openjdk11
7 | - oraclejdk11
8 | - openjdk8
9 |
10 | cache:
11 | directories:
12 | - $HOME/.m2
13 |
14 | install: true
15 |
16 | script:
17 | - travis_wait 30 mvn clean install -DskipTests=true -Dcheckstyle.skip=true -Dmaven.javadoc.skip=true
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # CHANGELOG
2 |
3 | ## v1.5.0
4 | - 新增 travis-ci.com 自动检测集成
5 | - 增加数据库类型和 org.apache.ibatis.type.JdbcType 的映射
6 | - 改善用户体验/可用性
7 | - 移除 guava 依赖
8 | - 修复添加类型转换未转大写的问题
9 | - 默认将数据库日期类型映射为 LocalDateTime
10 | - 新增支持作为 SpringBoot 子项目中使用
11 | - 增加 timestamp 和 org.apache.ibatis.type.JdbcType.TIMESTAMP 的映射
12 | - 内置 swagger vo 模板
13 | - 内置 mybatis plus 代码模板支持,支持直接生成 mybatis plus 代码模板
14 | - mapper 模板默认方法名简化
15 | - 需新增模板常量类 统一管理所有模板路径
16 |
17 | ## v1.5.1
18 | - 代码优化
19 | - 数据库表无注释情况默认处理为空字符串
20 | - 内置 oracle 数据库字段类型 NCLOB CLOB BLOB NVARCHAR2 转换
21 | - 优化生成类路径配置 支持每个类单独配置生成路径
22 | - 升级 mybatis 版本为 3.5.6, freemarker 版本为 2.3.30
23 | - 新增 lombok 代码模板
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Code-generator
2 | [](https://travis-ci.com/zhuyizhuo/code-generator)
3 | [](https://search.maven.org/search?q=g:com.github.zhuyizhuo)
4 | [](https://github.com/zhuyizhuo/code-generator/releases)
5 | 
6 | 
7 |
8 | ```
9 | 本项目致力于更简单易用的配置,更轻量快捷的生成代码.
10 | 一键生成 mybatis xml + model + mapper,并可自由扩展.
11 | ```
12 |
13 | ### 轻量级的代码生成器
14 |
15 | * 简单轻量
16 | * 配置化
17 | * 可扩展
18 |
19 | ### 支持的数据库
20 |
21 | * mysql
22 | * oracle
23 |
24 | ### 所需环境
25 |
26 | * JDK 1.8 +
27 |
28 | ### 在线文档
29 |
30 | - [在线文档](http://zhuyizhuo.online/code-generator-doc/)
31 |
32 | ### 版本号说明
33 | #### 生成器版本号的格式为 X.Y.Z(又称 Major.Minor.Patch),递增的规则为:
34 |
35 | ```
36 | X 表示主版本号,当 API 的兼容性变化时,X 递增,Y 和 Z 同时设置为 0。
37 | Y 表示次版本号,当增加功能(不影响 API 的兼容性) 或者 API 被标记为 Deprecated 时,Y 递增,同时 Z 设置为 0。
38 | Z 表示修订号,当功能优化或者当做 Bug 修复时(不影响 API 的兼容性),Z 递增。
39 | ```
40 |
41 | ### 未发布版本使用步骤
42 | 第一步:切换至对应分支,clone 项目至本地
43 | ```
44 | git clone https://github.com/zhuyizhuo/code-generator.git
45 | ```
46 | 第二步:进入项目目录执行以下命令,将项目安装至本地
47 | ```
48 | mvn clean install
49 | ```
50 |
51 | 第三步:按照 [在线文档](http://zhuyizhuo.online/code-generator-doc/) 使用即可
52 |
53 | ### 订阅更新
54 |
55 | Star [本项目](https://github.com/zhuyizhuo/code-generator),获取最新版本更新.
56 |
57 | ### 联系作者
58 |
59 | ```
60 | 如果在使用过程中遇到问题或者疑问,或提出改进建议,请联系作者.
61 | 添加请注明来源: code-generator
62 | ```
63 |
64 | #### 微信:
65 |
66 | 
67 |
--------------------------------------------------------------------------------
/TODO.md:
--------------------------------------------------------------------------------
1 | # 1.5.1
2 | - 代码优化
3 | - 优化 properties 文件加载
4 |
5 | - GeneratorBuilder.addJavaTemplate 方法是否可重命名 见名知意
6 |
7 | - 文档优化
8 | commonMethodNameFormatService 需配合各方法的 name-format 使用
9 |
10 | - 优化自定义生成器的使用 JavaModuleInfo 增加构造器使用 枚举类型
11 |
12 | # 1.6.0
13 | - 集成 slf4j 打印日志
14 | - 支持在模板中直接获取配置文件的配置
15 | - 支持 java 参数传入获取变量 #{xxx}
16 | - 提供 spring-boot starter 版本
17 | - 支持 yaml 配置
18 | - 增加属性,支持生成建表语句
19 | - 如使用自定义模板 可不校验映射 懒加载
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-architect
--------------------------------------------------------------------------------
/assets/1559619424122.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhuyizhuo/code-generator/e03116a527059085ce74ccab2426bc36df1e7c2d/assets/1559619424122.jpg
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 | * 此注解用来标识约定类
12 | * 用此注解配置的类 将会对类中的属性注入配置文件中的对应配置
13 | * 如果类中属性没有配置则赋值默认值
14 | *
15 | * @author zhuo
157 | * 按顺序依次获取配置,如果都未获取到 则返回空字符串
158 | *
159 | *
166 | * @param key 配置键
167 | * @return 按顺序依次获取配置,如果都未获取到 则返回空字符串
168 | */
169 | private String handleConfig(String key) {
170 | String property;
171 | if (customerProperties != null) {
172 | property = customerProperties.getProperty(key);
173 | if (GeneratorStringUtils.isNotBlank(property)){
174 | return property.trim();
175 | }
176 | }
177 | property = contextConfig.getProperty(key);
178 | if (GeneratorStringUtils.isNotBlank(property)){
179 | return property.trim();
180 | }
181 | property = System.getenv(key);
182 | if (GeneratorStringUtils.isNotBlank(property)) {
183 | return property.trim();
184 | }
185 | property = System.getProperty(key);
186 | return GeneratorStringUtils.isNotBlank(property) ? property.trim() : "";
187 | }
188 |
189 | private void doRegister() throws GeneratorException {
190 | if (classNames.isEmpty()) {return;}
191 | try {
192 | for (int i = 0; i < classNames.size(); i++) {
193 | String className = classNames.get(i);
194 |
195 | Class> clazz = Class.forName(className);
196 | if (clazz.isAnnotationPresent(CoventionClass.class)){
197 | String beanName = GeneratorStringUtils.firstLower(clazz.getSimpleName());
198 | beanMap.put(beanName, clazz.newInstance());
199 | }
200 | }
201 | } catch (Exception e) {
202 | LogUtils.error("doRegister error!Exception:" + e.getMessage());
203 | LogUtils.printException(e);
204 | throw new GeneratorException("doRegister error!Exception:" + e.getMessage());
205 | }
206 | }
207 |
208 | private void doLoadConfig(String contextConfigLocation) throws GeneratorException {
209 | ClassLoader classLoader = this.getClass().getClassLoader();
210 | InputStream resourceAsStream = classLoader.getResourceAsStream(contextConfigLocation);
211 | try {
212 | contextConfig.load(new BufferedReader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8)));
213 |
214 | resourceAsStream = classLoader.getResourceAsStream(resourceFile);
215 | Properties contextConfig = new Properties();
216 | contextConfig.load(resourceAsStream);
217 | String property = contextConfig.getProperty("generate.convention.sourceType");
218 | String[] split = property.split(",");
219 | this.classNames = Arrays.asList(split);
220 | } catch (IOException e) {
221 | LogUtils.error("doLoadConfig error!Exception:" + e.getMessage());
222 | LogUtils.printException(e);
223 | throw new GeneratorException("doLoadConfig error!Exception:" + e.getMessage());
224 | } finally {
225 | if (resourceAsStream != null) {
226 | try {
227 | resourceAsStream.close();
228 | } catch (IOException e) {
229 | LogUtils.printException(e);
230 | }
231 | }
232 | }
233 | }
234 |
235 | public static Checks if a CharSequence is whitespace, empty ("") or null. Checks if a CharSequence is not empty (""), not null and not whitespace only. 类型转换器
16 | * @since 1.4.0
17 | */
18 | @Documented
19 | @Retention(RetentionPolicy.RUNTIME)
20 | @Target({ElementType.TYPE})
21 | public @interface CoventionClass {
22 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/annotation/NotNull.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.annotation;
2 |
3 | import java.lang.annotation.Documented;
4 | import java.lang.annotation.ElementType;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | /**
10 | * 此注解用来标识 字段 方法属性 参数 不可为空
11 | *
12 | * @author zhuo
13 | * @since 1.4.0
14 | */
15 | @Documented
16 | @Retention(RetentionPolicy.CLASS)
17 | @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})
18 | public @interface NotNull {
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/annotation/Nullable.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.annotation;
2 |
3 | import java.lang.annotation.Documented;
4 | import java.lang.annotation.ElementType;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | /**
10 | * 此注解用来标识 字段 方法属性 参数 可为空
11 | *
12 | * @author zhuo
13 | * @since 1.4.0
14 | */
15 | @Documented
16 | @Retention(RetentionPolicy.CLASS)
17 | @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})
18 | public @interface Nullable {
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/annotation/Resource.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.annotation;
2 |
3 | import java.lang.annotation.Documented;
4 | import java.lang.annotation.ElementType;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | /**
10 | * 此注解用来标识资源文件
11 | *
12 | * @author zhuo
13 | * @since 1.4.0
14 | */
15 | @Target(ElementType.TYPE)
16 | @Retention(RetentionPolicy.RUNTIME)
17 | @Documented
18 | public @interface Resource {
19 |
20 | /**
21 | * 标识资源文件配置
22 | * @return 资源文件的配置 key
23 | */
24 | String value();
25 |
26 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/annotation/Value.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.annotation;
2 |
3 | import java.lang.annotation.Documented;
4 | import java.lang.annotation.ElementType;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | /**
10 | * 此注解用来标识资源配置
11 | *
12 | * @author zhuo
13 | * @since 1.4.0
14 | */
15 | @Target(ElementType.FIELD)
16 | @Retention(RetentionPolicy.RUNTIME)
17 | @Documented
18 | public @interface Value {
19 |
20 | /**
21 | * The actual value expression: e.g. "#{systemProperties.myProp}".
22 | * @return 对应 value 的配置 key
23 | */
24 | String value();
25 |
26 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/constants/ConfigConstants.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.constants;
2 |
3 | /**
4 | * 常量类
5 | *
6 | * @author zhuo
7 | * @since 1.0
8 | */
9 | public class ConfigConstants {
10 | public static final String DB_TYPE = "db.type";
11 | public static final String URL = "db.url";
12 | public static final String DRIVER = "db.driver";
13 | public static final String TABLE_SCHEMA = "db.table-schema";
14 | public static final String USERNAME = "db.username";
15 | public static final String PASSWORD = "db.password";
16 |
17 | public static final String GENERATE_TABLES_NAME = "generate.table-names";
18 | public static final String LOG_LEVEL = "generate.log.level";
19 | public static final String PARAMETER_TYPE_USE_TYPE_ALIASES = "generate.resources.xml.mybatis.parameter-type.aliases.enabled";
20 | public static final String TABLE_SEPARATOR = "generate.table.separator";
21 | public static final String FIELD_SEPARATOR = "generate.table.field.separator";
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/constants/LinkConstants.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.constants;
2 |
3 | /**
4 | * 链接配置常量
5 | *
6 | * @author zhuo
7 | * @since 1.5.0
8 | */
9 | public class LinkConstants {
10 | /** issue 地址 */
11 | public static final String ISSUE_URL = "https://github.com/zhuyizhuo/code-generator/issues";
12 | /** github 地址 */
13 | public static final String GITHUB_URL = "https://github.com/zhuyizhuo/code-generator/";
14 | /** 文档路径 */
15 | public static final String DOC_URL = "http://zhuyizhuo.online/code-generator-doc/\nGithub: " + GITHUB_URL;
16 | /** 常见问题 */
17 | public static final String FAQ_DOC_URL = "http://zhuyizhuo.online/code-generator-doc/guide/faq.html";
18 | /** 快速开始文档路径 */
19 | public static final String QUICKSTART_DOC_URL = "http://zhuyizhuo.online/code-generator-doc/guide/quickstart.html";
20 | /** 生成器扩展文档路径 */
21 | public static final String EXTENSION_DOC_BASE_URL = "http://zhuyizhuo.online/code-generator-doc/guide/extension.html";
22 | public static final String EXTENSION_DOC_URL_A = EXTENSION_DOC_BASE_URL + "#新增或修改数据库类型和 Java 类型映射";
23 | public static final String EXTENSION_DOC_URL_B = EXTENSION_DOC_BASE_URL + "#新增或修改数据库类型和 Mybatis JdbcType 映射";
24 | /** Maven 仓库地址 */
25 | public static final String MAVEN_REPOSITORY_URL = "https://search.maven.org/search";
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/constants/TemplateConstants.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.constants;
2 |
3 | /**
4 | * 模板常量类
5 | *
6 | * @author zhuo
7 | * @since 1.5.0
8 | */
9 | public class TemplateConstants {
10 | /** mybatis plus 相关模板*/
11 | public static final String XML_MYBATIS_PLUS = "/freemarker/template/java/mybatis_plus/xml_mybatis_plus.ftl";
12 | public static final String MAPPER_MYBATIS_PLUS = "/freemarker/template/java/mybatis_plus/mapper_mybatis_plus.ftl";
13 | public static final String MODEL_MYBATIS_PLUS = "/freemarker/template/java/mybatis_plus/model_mybatis_plus.ftl";
14 | public static final String MODEL_MYBATIS_PLUS_LOMBOK = "/freemarker/template/java/mybatis_plus/model_mybatis_plus_lombok.ftl";
15 | public static final String SERVICE_MYBATIS_PLUS = "/freemarker/template/java/mybatis_plus/service_mybatis_plus.ftl";
16 | public static final String SERVICE_IMPL_MYBATIS_PLUS = "/freemarker/template/java/mybatis_plus/service_impl_mybatis_plus.ftl";
17 |
18 | /** mysql 相关模板 */
19 | public static final String XML_MYSQL_HAS_PRIMARY_KEY = "/freemarker/template/xml/primary_key_mysql_mybatis_template.ftl";
20 | public static final String XML_MYSQL_NO_PRIMARY_KEY = "/freemarker/template/xml/no_primary_key_mysql_mybatis_template.ftl";
21 | public static final String MAPPER_MYSQL_HAS_PRIMARY_KEY = "/freemarker/template/java/primary_key_mysql_mapper_template.ftl";
22 | public static final String MAPPER_MYSQL_NO_PRIMARY_KEY = "/freemarker/template/java/no_primary_key_mysql_mapper_template.ftl";
23 |
24 | /** oracle 相关模板 */
25 | public static final String XML_ORACLE_HAS_PRIMARY_KEY = "/freemarker/template/xml/primary_key_oracle_mybatis_template.ftl";
26 | public static final String XML_ORACLE_NO_PRIMARY_KEY = "/freemarker/template/xml/no_primary_key_oracle_mybatis_template.ftl";
27 | public static final String MAPPER_ORACLE_HAS_PRIMARY_KEY = "/freemarker/template/java/primary_key_oracle_mapper_template.ftl";
28 | public static final String MAPPER_ORACLE_NO_PRIMARY_KEY = "/freemarker/template/java/no_primary_key_oracle_mapper_template.ftl";
29 |
30 | /** 数据对象 model 模板 */
31 | public static final String MODEL = "/freemarker/template/java/common/model.ftl";
32 | /** 数据对象 lombok model 模板 */
33 | public static final String MODEL_LOMBOK = "/freemarker/template/java/common/model_lombok.ftl";
34 | /** 数据对象 swagger + lombok VO 模板 */
35 | public static final String VO_SWAGGER_LOMBOK = "/freemarker/template/java/common/vo_swagger_lombok.ftl";
36 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/enums/DbTypeEnums.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.enums;
2 |
3 | /**
4 | * 数据库类型枚举
5 | *
6 | * @since 1.4.0
7 | */
8 | public enum DbTypeEnums {
9 | /** mysql 数据库 */
10 | MYSQL,
11 | /** oracle 数据库 */
12 | ORACLE,
13 | ;
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/enums/ErrorTypeEnums.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.enums;
2 |
3 | import com.github.zhuyizhuo.generator.constants.LinkConstants;
4 | import com.github.zhuyizhuo.generator.mybatis.generator.GeneratorBuilder;
5 | import org.apache.ibatis.parsing.GenericTokenParser;
6 | import org.apache.ibatis.parsing.TokenHandler;
7 |
8 | /**
9 | * 错误类型枚举
10 | *
11 | * @author zhuo
12 | * @since 1.5.0
13 | */
14 | public enum ErrorTypeEnums {
15 | /** 初始化配置失败! */
16 | INIT_CONFIG_ERROR("00001","","初始化配置失败!\n" +
17 | "可点击以下链接查找解决方案:\n" +
18 | "常见问题: " + LinkConstants.FAQ_DOC_URL + "\n" +
19 | "如果没有解决方案, 可提 ISSUE 反馈: " + LinkConstants.ISSUE_URL),
20 | /** 请检查是否添加对应数据库驱动依赖! */
21 | CHECK_DEPENDENCE("00002","Error setting driver on UnpooledDataSource.","请检查是否添加对应数据库驱动依赖!\n" +
22 | "示例: \n" +
23 | "mysql 8.0.20 依赖: \n" +
24 | "
8 | * @version 1.4.0
9 | */
10 | public enum FileTypeEnums {
11 | JAVA,
12 | XML,
13 | ;
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/enums/LogLevelEnums.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.enums;
2 |
3 | /**
4 | * 日志级别枚举
5 | *
6 | * @since 1.5.0
7 | */
8 | public enum LogLevelEnums {
9 | /** 打印堆栈 */
10 | DEBUG(1),
11 | /** 普通日志 */
12 | INFO(2),
13 | ;
14 |
15 | private int level;
16 |
17 | LogLevelEnums(int level) {
18 | this.level = level;
19 | }
20 |
21 | public int getLevel() {
22 | return level;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/enums/MethodEnums.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.enums;
2 |
3 | /**
4 | * 方法枚举
5 | *
6 | * @author zhuo
7 | * @since 1.4.0
8 | */
9 | public enum MethodEnums {
10 | /** 新增方法 */
11 | INSERT("generate.java.method.insert."),
12 | /** 批量新增方法*/
13 | BATCH_INSERT("generate.java.method.batch-insert."),
14 | /** 删除方法 */
15 | DELETE_BY_WHERE("generate.java.method.delete-by-where."),
16 | /** 根据主键删除方法 */
17 | DELETE_BY_PRIMARY_KEY("generate.java.method.delete-by-primary-key."),
18 | /** 根据主键更新方法 */
19 | UPDATE_BY_PRIMARY_KEY("generate.java.method.update-by-primary-key."),
20 | /** 查询方法 */
21 | QUERY_BY_WHERE("generate.java.method.query-by-where."),
22 | /** 根据主键查询 */
23 | QUERY_BY_PRIMARY_KEY("generate.java.method.select-one-by-primary-key."),
24 | /** 查询总数方法 */
25 | COUNT_BY_WHERE("generate.java.method.count-by-where."),
26 | /** 所有方法 */
27 | ALL_METHOD
28 | ;
29 |
30 | private String propertiesBaseKey;
31 |
32 | /** 配置是否生成方法 */
33 | private String propertiesEnabledKey = "enabled";
34 | /** 方法注释配置 */
35 | private String methodCommentKey = "comment";
36 | /** 默认格式化方式 */
37 | private String methodFormatKey = "name-format";
38 |
39 | MethodEnums() {
40 | }
41 |
42 | MethodEnums(String propertiesBaseKey) {
43 | this.propertiesBaseKey = propertiesBaseKey;
44 | }
45 |
46 | public String getPropertiesEnabledKey() {
47 | return propertiesBaseKey + propertiesEnabledKey;
48 | }
49 |
50 | public String getMethodCommentKey() {
51 | return propertiesBaseKey + methodCommentKey;
52 | }
53 |
54 | public String getMethodFormatKey() {
55 | return propertiesBaseKey + methodFormatKey;
56 | }
57 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/enums/ModuleTypeEnums.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.enums;
2 |
3 | /**
4 | * 模块类型枚举
5 | * create time: 2020-10-29 08:25:15
6 | *
7 | * @author zhuo
8 | * @since 1.5.0
9 | */
10 | public enum ModuleTypeEnums {
11 |
12 | /** 控制层 */
13 | CONTROLLER(FileTypeEnums.JAVA,"generate.java.module.controller","控制层"),
14 | /** 视图对象 */
15 | VO(FileTypeEnums.JAVA,"generate.java.module.vo","视图对象"),
16 | /** 服务接口 */
17 | SERVICE(FileTypeEnums.JAVA,"generate.java.module.service","服务接口"),
18 | /** 服务接口实现 */
19 | SERVICE_IMPL(FileTypeEnums.JAVA,"generate.java.module.service.impl","服务接口实现"),
20 | /** 数据库接口 */
21 | MAPPER(FileTypeEnums.JAVA,"generate.java.module.mapper","数据库接口"),
22 | /** 数据对象 */
23 | MODEL(FileTypeEnums.JAVA,"generate.java.module.model","数据对象"),
24 | /** mybatis xml 文件 */
25 | XML(FileTypeEnums.XML,"generate.resources.xml","mybatis xml 文件"),
26 | ;
27 |
28 | /** 文件类型 */
29 | private FileTypeEnums fileType;
30 | /** 配置前缀 */
31 | private String prefix;
32 | /** 模块描述 */
33 | private String description;
34 |
35 | ModuleTypeEnums(FileTypeEnums typeEnums, String prefix, String description) {
36 | this.fileType = typeEnums;
37 | this.prefix = prefix;
38 | this.description = description;
39 | }
40 |
41 | public FileTypeEnums getFileType() {
42 | return fileType;
43 | }
44 |
45 | public String getPrefix() {
46 | return prefix;
47 | }
48 | public String getDescription() {
49 | return description;
50 | }
51 |
52 | /** 生成文件的文件名格式化配置 */
53 | private String fileNameFormat = ".name-format";
54 | /** 生成文件的包路径配置 */
55 | private String filePackage = ".package";
56 | /** 生成文件的输出路径 */
57 | private String outputPath = ".out-put-path";
58 |
59 | public String getFileNameFormatKey() {
60 | return prefix + fileNameFormat;
61 | }
62 |
63 | public String getFilePackageKey() {
64 | return prefix + filePackage;
65 | }
66 |
67 | public String getOutputPathKey() {
68 | return prefix + outputPath;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/enums/TemplateTypeEnums.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.enums;
2 |
3 | /**
4 | * 模板类型枚举
5 | *
6 | * @author zhuo
7 | * @since 1.5.0
8 | */
9 | public enum TemplateTypeEnums {
10 | /** mysql数据库 */
11 | MYSQL,
12 | ORACLE,
13 | MYBATIS_PLUS,
14 | ;
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/exception/GeneratorException.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.exception;
2 |
3 | /**
4 | * 自定义生成器异常
5 | *
6 | * @author zhuo
7 | * @since 1.5.0
8 | */
9 | public class GeneratorException extends RuntimeException{
10 |
11 | /** 异常信息 */
12 | private String message;
13 |
14 | public GeneratorException(String message) {
15 | this.message = message;
16 | }
17 |
18 | @Override
19 | public String getMessage() {
20 | return message;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/convention/ClassCommentInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.convention;
2 |
3 | import com.github.zhuyizhuo.generator.annotation.CoventionClass;
4 | import com.github.zhuyizhuo.generator.annotation.Value;
5 |
6 | import java.text.SimpleDateFormat;
7 | import java.util.Date;
8 |
9 | /**
10 | * 类注释
11 | * time: 2018/7/29 16:10
12 | *
13 | * @author zhuo
14 | * @since 1.0
15 | */
16 | @CoventionClass
17 | public class ClassCommentInfo {
18 | /** 文件创建时版本号 */
19 | @Value("#{generate.java.comment.since-version}")
20 | private String sinceVersion;
21 | /** 当前版本号 */
22 | @Value("#{generate.java.comment.current-version}")
23 | private String version;
24 | /** 作者 */
25 | @Value("#{generate.java.comment.author}")
26 | private String author;
27 | /** 默认生成时间 */
28 | private String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
29 |
30 | public String getVersion() {
31 | return version;
32 | }
33 |
34 | public void setVersion(String version) {
35 | this.version = version;
36 | }
37 |
38 | public String getAuthor() {
39 | return author;
40 | }
41 |
42 | public void setAuthor(String author) {
43 | this.author = author;
44 | }
45 |
46 | public String getCreateTime() {
47 | return createTime;
48 | }
49 |
50 | public void setCreateTime(String createTime) {
51 | this.createTime = createTime;
52 | }
53 |
54 | public String getSinceVersion() {
55 | return sinceVersion;
56 | }
57 |
58 | public void setSinceVersion(String sinceVersion) {
59 | this.sinceVersion = sinceVersion;
60 | }
61 |
62 | @Override
63 | public String toString() {
64 | return "ClassCommentInfo{" +
65 | "sinceVersion='" + sinceVersion + '\'' +
66 | ", version='" + version + '\'' +
67 | ", author='" + author + '\'' +
68 | ", createTime='" + createTime + '\'' +
69 | '}';
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/convention/FileOutPathInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.convention;
2 |
3 | import com.github.zhuyizhuo.generator.annotation.CoventionClass;
4 | import com.github.zhuyizhuo.generator.annotation.Value;
5 | import com.github.zhuyizhuo.generator.enums.FileTypeEnums;
6 | import com.github.zhuyizhuo.generator.enums.ModuleTypeEnums;
7 | import com.github.zhuyizhuo.generator.mybatis.dto.JavaClassDefinition;
8 | import com.github.zhuyizhuo.generator.mybatis.generator.extension.CustomizeModuleInfo;
9 | import com.github.zhuyizhuo.generator.mybatis.generator.extension.FormatService;
10 | import com.github.zhuyizhuo.generator.mybatis.generator.extension.JavaModuleInfo;
11 | import com.github.zhuyizhuo.generator.mybatis.generator.support.ContextHolder;
12 | import com.github.zhuyizhuo.generator.mybatis.generator.support.ModuleInfo;
13 |
14 | import java.text.MessageFormat;
15 | import java.util.ArrayList;
16 | import java.util.List;
17 | import java.util.Map;
18 | import java.util.concurrent.ConcurrentHashMap;
19 |
20 | /**
21 | * 包路径及文件输出路径信息
22 | *
23 | * @author zhuo
24 | * @since 1.0
25 | */
26 | @CoventionClass
27 | public class FileOutPathInfo {
28 |
29 | @Value("#{generate.base.out-put-path}")
30 | private String baseOutputPath;
31 | /** true 则生成完整目录 false 则仅生成目录最后一层 */
32 | @Value("#{generate.java.base.package.enabled}")
33 | private String basePackageEnabled;
34 |
35 | private String tableName;
36 | private String tableNameCamelCase;
37 | /**
38 | * 类名格式化 Service Map
39 | * ModuleType -> 类名格式化 Service
40 | */
41 | private Map
5 | * time 2018/7/27 21:43
6 | * @author zhuo
7 | * @version 1.0
8 | */
9 | public class ColumnInfo {
10 | /** 列名 */
11 | private String columnName;
12 | /** 数据库字段类型 */
13 | private String dataType;
14 | /** 字段备注 */
15 | private String columnComment;
16 | /** 是否主键 */
17 | private boolean primaryKey;
18 |
19 | public ColumnInfo() {
20 | }
21 |
22 | public String getColumnName() {
23 | return columnName;
24 | }
25 |
26 | public void setColumnName(String columnName) {
27 | this.columnName = columnName;
28 | }
29 |
30 | public String getDataType() {
31 | return dataType;
32 | }
33 |
34 | public void setDataType(String dataType) {
35 | this.dataType = dataType;
36 | }
37 |
38 | public String getColumnComment() {
39 | return columnComment;
40 | }
41 |
42 | public void setColumnComment(String columnComment) {
43 | this.columnComment = columnComment;
44 | }
45 |
46 | public boolean isPrimaryKey() {
47 | return primaryKey;
48 | }
49 |
50 | public void setPrimaryKey(boolean primaryKey) {
51 | this.primaryKey = primaryKey;
52 | }
53 |
54 | @Override
55 | public String toString() {
56 | return "ColumnInfo{" +
57 | "columnName='" + columnName + '\'' +
58 | ", dataType='" + dataType + '\'' +
59 | ", columnComment='" + columnComment + '\'' +
60 | ", primaryKey=" + primaryKey +
61 | '}';
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/database/entity/DataBaseInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.database.entity;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * 表信息
7 | * @author zhuo
8 | * @version 1.0
9 | * time: 2018/7/29 19:16
10 | */
11 | public class DataBaseInfo {
12 | /** 数据库名称 */
13 | private String tableSchema;
14 | /** 表名 */
15 | private List
16 | * time: 2018/7/30 12:57
17 | *
18 | * @author zhuo
19 | * @version 1.0
20 | */
21 | public class DbServiceFactory {
22 |
23 | private static Map
9 | * time: 2018/7/30 12:56
10 | *
11 | * @author zhuo
12 | * @version 1.0
13 | */
14 | public interface DbService {
15 |
16 | /**
17 | * 查询数据库表信息及列信息
18 | * @return 数据库表信息 list
19 | */
20 | List
19 | * time: 2018/7/30 13:12
20 | *
21 | * @author zhuo
22 | * @version 1.0
23 | */
24 | public abstract class AbstractDbService implements DbService {
25 |
26 | protected DataBaseInfo getDataBaseInfo() {
27 | DataBaseInfo tableInfo = new DataBaseInfo();
28 | tableInfo.setTableSchema(getTableSchema());
29 | tableInfo.setTableNames(getTableNames());
30 | return tableInfo;
31 | }
32 |
33 | protected String getTableSchema() {
34 | return ContextHolder.getConfig(ConfigConstants.TABLE_SCHEMA);
35 | }
36 |
37 | protected List
19 | * time: 2018/7/30 13:10
20 | *
21 | * @author zhuo
22 | * @version 1.0
23 | */
24 | public class MysqlDbServiceImpl extends AbstractDbService {
25 |
26 | @Override
27 | public List
23 | * time: 2018/8/6 12:58
24 | *
25 | * @author zhuo
26 | * @version 1.0
27 | */
28 | public class OracleDbServiceImpl extends AbstractDbService {
29 |
30 | @Override
31 | protected String getTableSchema() {
32 | String tableSchema = super.getTableSchema();
33 | if (GeneratorStringUtils.isNotBlank(tableSchema)){
34 | return tableSchema.toUpperCase();
35 | }
36 | return tableSchema;
37 | }
38 |
39 | @Override
40 | protected List
5 | * time: 2019/5/23
6 | *
7 | * @author zhuo
8 | * @since 1.4.0
9 | */
10 | public class JavaClassDefinition {
11 | /** 包路径 */
12 | private String fullPackage;
13 | /** 类名 */
14 | private String className;
15 |
16 | public JavaClassDefinition() {
17 | }
18 |
19 | public JavaClassDefinition(String fullPackage, String className) {
20 | this.fullPackage = fullPackage;
21 | this.className = className;
22 | }
23 |
24 | public String getFullPackage() {
25 | return fullPackage;
26 | }
27 |
28 | public void setFullPackage(String fullPackage) {
29 | this.fullPackage = fullPackage;
30 | }
31 |
32 | public String getClassName() {
33 | return className;
34 | }
35 |
36 | public void setClassName(String className) {
37 | this.className = className;
38 | }
39 |
40 | @Override
41 | public String toString() {
42 | return "JavaClassDefinition{" +
43 | "fullPackage='" + fullPackage + '\'' +
44 | ", className='" + className + '\'' +
45 | '}';
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/dto/JavaColumnInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.dto;
2 |
3 | import com.github.zhuyizhuo.generator.mybatis.database.entity.ColumnInfo;
4 |
5 | /**
6 | * java字段实体
7 | * time: 2018/7/29 16:06
8 | *
9 | * @author zhuo
10 | * @version 1.0
11 | */
12 | public class JavaColumnInfo extends ColumnInfo {
13 | /** 转为驼峰命名后的字段名 */
14 | private String javaColumnName;
15 | /** java字段类型 */
16 | private String javaDataType;
17 | /** java字段类型全称 */
18 | private String javaDataTypeFullPath;
19 |
20 | public JavaColumnInfo() {
21 | }
22 |
23 | public String getJavaColumnName() {
24 | return javaColumnName;
25 | }
26 |
27 | public void setJavaColumnName(String javaColumnName) {
28 | this.javaColumnName = javaColumnName;
29 | }
30 |
31 | public String getJavaDataType() {
32 | return javaDataType;
33 | }
34 |
35 | public void setJavaDataType(String javaDataType) {
36 | this.javaDataType = javaDataType;
37 | }
38 |
39 | public String getJavaDataTypeFullPath() {
40 | return javaDataTypeFullPath;
41 | }
42 |
43 | public void setJavaDataTypeFullPath(String javaDataTypeFullPath) {
44 | this.javaDataTypeFullPath = javaDataTypeFullPath;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return "JavaColumnInfo{" +
50 | "javaColumnName='" + javaColumnName + '\'' +
51 | ", javaDataType='" + javaDataType + '\'' +
52 | ", javaDataTypeFullPath='" + javaDataTypeFullPath + '\'' +
53 | '}';
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/dto/MethodDescription.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.dto;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * 方法描述
8 | * time: 2019/5/21
9 | * @author zhuo
10 | * @since 1.4.0
11 | */
12 | public class MethodDescription {
13 | /** 是否生成方法 */
14 | private boolean enabled;
15 | /** 方法名 */
16 | private String methodName;
17 | /** 方法注释 */
18 | private String comment;
19 | /** 方法参数 */
20 | private List
10 | *
11 | * @author zhuo
12 | * @since 1.3.2
13 | */
14 | public class MybatisXmlDefinition {
15 | /** 命名空间 */
16 | private String nameSpace;
17 | /** 结果集 */
18 | private ResultMapDefinition resultMap;
19 | /** xml 参数类型 -> method 关联? */
20 | private String parameterType;
21 | /** 列信息定义 */
22 | private List
7 | * time: 2019-5-29
8 | *
9 | * @author zhuo
10 | * @since 1.4.0
11 | */
12 | public class CustomizeModuleInfo {
13 | /** 模块 例如 controller service 等 */
14 | private String moduleType;
15 | /** 模板路径 使用模板生成时 需要传入模板路径 */
16 | private String templatePath;
17 | /**
18 | * 文件输出路径模板 如果单表生成 也可直接写为真实文件输出全路径
19 | *
20 | * @See java.text.MessageFormat#format(java.lang.String, java.lang.Object...)
21 | * outPutFullPathFormatPattern 为 第一个参数
22 | * 文件名为第二个参数
23 | */
24 | private String outPutFullPathFormatPattern;
25 | /**
26 | * 文件名格式化 例如 {0}Mapper 适用于批量及单表生成
27 | * 或直接指定文件名 例如 UserMapper 仅适用于单表生成
28 | *
29 | * @See java.text.MessageFormat#format(java.lang.String, java.lang.Object...)
30 | * fileNameFormatPattern 为第一个参数
31 | * 表名转驼峰命名 为第二个参数
32 | *
33 | * 也可使用 GeneratorBuilder.addModuleNameFormat(moduleType,moduleNameFormatService)
34 | * 自定义本 moduleType 对应的文件名格式化 service
35 | *
36 | * 自定义 service 之后,本配置自动失效
37 | */
38 | private String fileNameFormatPattern;
39 |
40 | public CustomizeModuleInfo(String moduleType, String templatePath, String outPutFullPathFormatPattern, String fileNameFormatPattern) {
41 | CheckUtils.assertNotNull(moduleType,"moduleType must not null!");
42 | CheckUtils.assertNotNull(templatePath,"templatePath must not null!");
43 | CheckUtils.assertNotNull(outPutFullPathFormatPattern,"outPutFullPathFormatPattern must not null!");
44 | CheckUtils.assertNotNull(fileNameFormatPattern,"fileNameFormatPattern must not null!");
45 |
46 | this.moduleType = moduleType;
47 | this.templatePath = templatePath;
48 | this.outPutFullPathFormatPattern = outPutFullPathFormatPattern;
49 | this.fileNameFormatPattern = fileNameFormatPattern;
50 | }
51 |
52 | public String getModuleType() {
53 | return moduleType;
54 | }
55 |
56 | public String getTemplatePath() {
57 | return templatePath;
58 | }
59 |
60 | public String getOutPutFullPathFormatPattern() {
61 | return outPutFullPathFormatPattern;
62 | }
63 |
64 | public String getFileNameFormatPattern() {
65 | return fileNameFormatPattern;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/generator/extension/FormatService.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.generator.extension;
2 |
3 | /**
4 | * 名称格式化
5 | * time: 2018/8/16 19:29
6 | *
7 | * @author zhuo
8 | * @since 1.0
9 | * @version 1.4.0
10 | */
11 | public interface FormatService {
12 |
13 | /**
14 | * name 格式化
15 | * @param tableName 数据库表名
16 | * @return 格式化后的名称
17 | */
18 | String format(String tableName);
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/generator/extension/JavaModuleInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.generator.extension;
2 |
3 | import com.github.zhuyizhuo.generator.annotation.NotNull;
4 | import com.github.zhuyizhuo.generator.utils.CheckUtils;
5 |
6 | /**
7 | * 扩展 java 模块信息
8 | * time: 2019/5/27
9 | *
10 | * @author zhuo
11 | * @since 1.4.0
12 | */
13 | public class JavaModuleInfo {
14 | /** 模块 例如 controller service 等 */
15 | private String moduleType;
16 | /** 模板路径 使用模板生成时 需要传入模板路径 */
17 | private String templatePath;
18 | /** 类的包路径 例如 com.baidu **/
19 | private String classPackage;
20 | /** 输出路径 */
21 | private String outputPath;
22 | /**
23 | * 文件名格式化 例如 {0}Mapper 适用于批量及单表生成
24 | * 或直接指定文件名 例如 UserMapper 仅适用于单表生成
25 | */
26 | private String classNameFormat;
27 |
28 | public JavaModuleInfo(@NotNull String moduleType, @NotNull String templatePath,
29 | @NotNull String classPackage, @NotNull String outputPath, @NotNull String classNameFormat) {
30 | CheckUtils.assertNotNull(moduleType,"moduleType must not null!");
31 | CheckUtils.assertNotNull(templatePath,"templatePath must not null!");
32 | CheckUtils.assertNotNull(classPackage,"classPackage must not null!");
33 | CheckUtils.assertNotNull(outputPath,"outputPath must not null!");
34 | CheckUtils.assertNotNull(classNameFormat,"classNameFormat must not null!");
35 |
36 | this.moduleType = moduleType;
37 | this.templatePath = templatePath;
38 | this.classPackage = classPackage;
39 | this.outputPath = outputPath;
40 | this.classNameFormat = classNameFormat;
41 | }
42 |
43 | public String getModuleType() {
44 | return moduleType;
45 | }
46 |
47 | public String getTemplatePath() {
48 | return templatePath;
49 | }
50 |
51 | public String getClassPackage() {
52 | return classPackage;
53 | }
54 |
55 | public String getClassNameFormat() {
56 | return classNameFormat;
57 | }
58 |
59 | public String getOutputPath() {
60 | return outputPath;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/generator/extension/LogService.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.generator.extension;
2 |
3 | import com.github.zhuyizhuo.generator.mybatis.vo.GenerateInfo;
4 |
5 | /**
6 | * 日志输出, 打印生成模板的元数据
7 | * time: 2019/6/6
8 | *
9 | * @author zhuo
10 | */
11 | public interface LogService {
12 |
13 | /**
14 | * 输出生成信息
15 | * @param generateInfo 生成器处理后的生成数据使用的元数据
16 | */
17 | void logGenerateInfo(GenerateInfo generateInfo);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/generator/factory/GenerateServiceFactory.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.generator.factory;
2 |
3 | import com.github.zhuyizhuo.generator.constants.ConfigConstants;
4 | import com.github.zhuyizhuo.generator.enums.DbTypeEnums;
5 | import com.github.zhuyizhuo.generator.enums.TemplateTypeEnums;
6 | import com.github.zhuyizhuo.generator.exception.GeneratorException;
7 | import com.github.zhuyizhuo.generator.mybatis.generator.service.GenerateService;
8 | import com.github.zhuyizhuo.generator.mybatis.generator.service.template.freemarker.impl.MybatisPlusGenerateImpl;
9 | import com.github.zhuyizhuo.generator.mybatis.generator.service.template.freemarker.impl.MysqlGenerateImpl;
10 | import com.github.zhuyizhuo.generator.mybatis.generator.service.template.freemarker.impl.OracleGenerateImpl;
11 | import com.github.zhuyizhuo.generator.mybatis.generator.support.ContextHolder;
12 | import com.github.zhuyizhuo.generator.utils.LogUtils;
13 |
14 | import java.util.Map;
15 | import java.util.concurrent.ConcurrentHashMap;
16 |
17 | /**
18 | * 生成器工厂
19 | * time: 2019/5/28
20 | *
21 | * @author zhuo
22 | * @since 1.4.0
23 | */
24 | public class GenerateServiceFactory {
25 |
26 | private static Map
7 | *
8 | * @author zhuo
9 | * @since 1.4.0
10 | */
11 | public interface GenerateService {
12 |
13 | /**
14 | * 文件生成
15 | * @param generateMetaData 生成所需元数据
16 | */
17 | void generate(GenerateMetaData generateMetaData);
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/generator/service/template/TemplateGenerateService.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.generator.service.template;
2 |
3 | import com.github.zhuyizhuo.generator.mybatis.generator.service.GenerateService;
4 |
5 | /**
6 | * 模板生成 service
7 | *
8 | * @author zhuo
9 | * @since 1.4.0
10 | */
11 | public interface TemplateGenerateService extends GenerateService {
12 |
13 | /**
14 | * 增加模板
15 | * @param moduleType 模块类型
16 | * @param templatePath 模板路径
17 | */
18 | void addTemplate(String moduleType,String templatePath);
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/generator/service/template/freemarker/FreemarkerGenerateService.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.generator.service.template.freemarker;
2 |
3 | import com.github.zhuyizhuo.generator.enums.TemplateTypeEnums;
4 | import com.github.zhuyizhuo.generator.enums.ModuleTypeEnums;
5 | import com.github.zhuyizhuo.generator.mybatis.generator.service.template.TemplateGenerateService;
6 | import com.github.zhuyizhuo.generator.mybatis.vo.GenerateInfo;
7 | import com.github.zhuyizhuo.generator.mybatis.vo.GenerateMetaData;
8 | import com.github.zhuyizhuo.generator.mybatis.vo.ModulePathInfo;
9 | import com.github.zhuyizhuo.generator.mybatis.vo.TableInfo;
10 | import com.github.zhuyizhuo.generator.utils.Freemarker;
11 | import com.github.zhuyizhuo.generator.utils.GeneratorStringUtils;
12 | import com.github.zhuyizhuo.generator.utils.LogUtils;
13 |
14 | import java.util.List;
15 | import java.util.Map;
16 | import java.util.concurrent.ConcurrentHashMap;
17 |
18 | /**
19 | * freemarker 模板生成
20 | */
21 | public abstract class FreemarkerGenerateService implements TemplateGenerateService {
22 | /**
23 | * TemplateType_moduleType_hasPrivateKey -> templatePath
24 | */
25 | private Map
10 | * create time: 2020-10-28 21:37:06
11 | *
12 | * @author zhuo
13 | * @since 1.5.0
14 | */
15 | public class MybatisPlusGenerateImpl extends FreemarkerGenerateService {
16 |
17 | public MybatisPlusGenerateImpl() {
18 | addTemplatePath(ModuleTypeEnums.XML, TemplateConstants.XML_MYBATIS_PLUS);
19 |
20 | addTemplatePath(ModuleTypeEnums.MAPPER, TemplateConstants.MAPPER_MYBATIS_PLUS);
21 |
22 | addTemplatePath(ModuleTypeEnums.MODEL, TemplateConstants.MODEL_MYBATIS_PLUS);
23 |
24 | addTemplatePath(ModuleTypeEnums.SERVICE, TemplateConstants.SERVICE_MYBATIS_PLUS);
25 |
26 | addTemplatePath(ModuleTypeEnums.SERVICE_IMPL, TemplateConstants.SERVICE_IMPL_MYBATIS_PLUS);
27 | }
28 |
29 | @Override
30 | protected TemplateTypeEnums getTemplateType() {
31 | return TemplateTypeEnums.MYBATIS_PLUS;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/generator/service/template/freemarker/impl/MysqlGenerateImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.generator.service.template.freemarker.impl;
2 |
3 | import com.github.zhuyizhuo.generator.constants.TemplateConstants;
4 | import com.github.zhuyizhuo.generator.enums.ModuleTypeEnums;
5 | import com.github.zhuyizhuo.generator.enums.TemplateTypeEnums;
6 | import com.github.zhuyizhuo.generator.mybatis.generator.service.template.freemarker.FreemarkerGenerateService;
7 |
8 | /**
9 | * mysql 模板生成
10 | *
11 | * @author zhuo
12 | * @since 1.4.0
13 | */
14 | public class MysqlGenerateImpl extends FreemarkerGenerateService {
15 |
16 | public MysqlGenerateImpl() {
17 | addTemplatePath(ModuleTypeEnums.XML,true, TemplateConstants.XML_MYSQL_HAS_PRIMARY_KEY);
18 | addTemplatePath(ModuleTypeEnums.XML,false, TemplateConstants.XML_MYSQL_NO_PRIMARY_KEY);
19 |
20 | addTemplatePath(ModuleTypeEnums.MAPPER,true, TemplateConstants.MAPPER_MYSQL_HAS_PRIMARY_KEY);
21 | addTemplatePath(ModuleTypeEnums.MAPPER,false, TemplateConstants.MAPPER_MYSQL_NO_PRIMARY_KEY);
22 |
23 | addTemplatePath(ModuleTypeEnums.MODEL, TemplateConstants.MODEL);
24 | }
25 |
26 | @Override
27 | protected TemplateTypeEnums getTemplateType() {
28 | return TemplateTypeEnums.MYSQL;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/generator/service/template/freemarker/impl/OracleGenerateImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.generator.service.template.freemarker.impl;
2 |
3 | import com.github.zhuyizhuo.generator.constants.TemplateConstants;
4 | import com.github.zhuyizhuo.generator.enums.ModuleTypeEnums;
5 | import com.github.zhuyizhuo.generator.enums.TemplateTypeEnums;
6 | import com.github.zhuyizhuo.generator.mybatis.generator.service.template.freemarker.FreemarkerGenerateService;
7 |
8 | /**
9 | * oracle 模板生成
10 | *
11 | * @author zhuo
12 | * @since 1.4.0
13 | */
14 | public class OracleGenerateImpl extends FreemarkerGenerateService {
15 |
16 | public OracleGenerateImpl() {
17 | addTemplatePath(ModuleTypeEnums.XML,true, TemplateConstants.XML_ORACLE_HAS_PRIMARY_KEY);
18 | addTemplatePath(ModuleTypeEnums.XML,false, TemplateConstants.XML_ORACLE_NO_PRIMARY_KEY);
19 |
20 | addTemplatePath(ModuleTypeEnums.MAPPER,true, TemplateConstants.MAPPER_ORACLE_HAS_PRIMARY_KEY);
21 | addTemplatePath(ModuleTypeEnums.MAPPER,false, TemplateConstants.MAPPER_ORACLE_NO_PRIMARY_KEY);
22 |
23 | addTemplatePath(ModuleTypeEnums.MODEL, TemplateConstants.MODEL);
24 | }
25 |
26 | @Override
27 | protected TemplateTypeEnums getTemplateType() {
28 | return TemplateTypeEnums.ORACLE;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/generator/support/ContextHolder.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.generator.support;
2 |
3 | import com.github.zhuyizhuo.generator.annotation.CoventionClass;
4 | import com.github.zhuyizhuo.generator.annotation.Resource;
5 | import com.github.zhuyizhuo.generator.annotation.Value;
6 | import com.github.zhuyizhuo.generator.exception.GeneratorException;
7 | import com.github.zhuyizhuo.generator.utils.GeneratorStringUtils;
8 | import com.github.zhuyizhuo.generator.utils.LogUtils;
9 | import org.apache.ibatis.parsing.GenericTokenParser;
10 | import org.apache.ibatis.parsing.TokenHandler;
11 |
12 | import java.io.BufferedReader;
13 | import java.io.IOException;
14 | import java.io.InputStream;
15 | import java.io.InputStreamReader;
16 | import java.lang.reflect.Field;
17 | import java.nio.charset.StandardCharsets;
18 | import java.util.ArrayList;
19 | import java.util.Arrays;
20 | import java.util.Enumeration;
21 | import java.util.List;
22 | import java.util.Map;
23 | import java.util.Properties;
24 | import java.util.concurrent.ConcurrentHashMap;
25 |
26 | /**
27 | * 配置扫描 自动装配
28 | *
32 | * time: 2019/5/23
33 | *
34 | * @author zhuo
29 | * 扫描在 generator.properties 中配置的装配类(全路径),
30 | * 如果类上存在 CoventionClass 注解,则会对类中 @Value 标注的属性注入配置文件的对应配置。
31 | *
35 | * @since 1.4.0
36 | */
37 | @Resource("generate-config.properties")
38 | public class ContextHolder {
39 |
40 | private final static String resourceFile = "generator.properties";
41 | /** 系统默认配置信息 */
42 | private static Properties contextConfig = new Properties();
43 | /** 生成器配置对象 map */
44 | private static Map
160 | * 优先级:
161 | * 1. 先获取用户的 java 配置
162 | * 2. 获取配置文件配置
163 | * 3. 获取环境变量
164 | * 4. 获取系统变量
165 | *
12 | * time: 2019/5/27
13 | *
14 | * @author zhuo
15 | * @since 1.4.0
16 | */
17 | public class ModuleInfo {
18 | /** 模块类型 */
19 | private String moduleType;
20 | /** 文件类型 */
21 | private FileTypeEnums fileType;
22 | /** 文件包路径 仅 java 模块需设置包路径 */
23 | private String fileFullPackage;
24 | /**
25 | * 文件名格式化
26 | * 例如 {0}Mapper
27 | * @See java.text.MessageFormat#format(java.lang.String, java.lang.Object...)
28 | * fileNameFormatPattern 为第一个参数
29 | * 表名转驼峰命名 为第二个参数
30 | *
31 | * 优先级低于 ModuleInfo#fileNameFormatServie
32 | * 如果设置了 fileNameFormatServie 则 该配置自动失效
33 | */
34 | private String fileNameFormatPattern;
35 | /**
36 | * 文件输出路径模板
37 | * @See java.text.MessageFormat#format(java.lang.String, java.lang.Object...)
38 | * outPutFullPathFormatPattern 为 第一个参数
39 | * 文件名为第二个参数
40 | */
41 | private String outPutFullPathFormatPattern;
42 | /**
43 | * 文件名格式化 service
44 | * 可使用 GeneratorBuilder.addModuleNameFormat(moduleType,moduleNameFormatService)
45 | * 自定义文件名格式化 Service
46 | */
47 | private FormatService fileNameFormatServie;
48 | /**
49 | * 文件输出全路径
50 | * 将文件输出路径模板格式化后 设置
51 | */
52 | private String outPutFullPath;
53 |
54 | public String getModuleType() {
55 | return moduleType;
56 | }
57 |
58 | public void setModuleType(String moduleType) {
59 | this.moduleType = moduleType;
60 | }
61 |
62 | public String getFileFullPackage() {
63 | return fileFullPackage;
64 | }
65 |
66 | public void setFileFullPackage(String fileFullPackage) {
67 | this.fileFullPackage = fileFullPackage;
68 | }
69 |
70 | public String getOutPutFullPathFormatPattern() {
71 | return outPutFullPathFormatPattern;
72 | }
73 |
74 | public void setOutPutFullPathFormatPattern(String outPutFullPathFormatPattern) {
75 | this.outPutFullPathFormatPattern = outPutFullPathFormatPattern;
76 | }
77 |
78 | public FormatService getFileNameFormatServie() {
79 | return fileNameFormatServie;
80 | }
81 |
82 | public void setFileNameFormatServie(FormatService fileNameFormatServie) {
83 | this.fileNameFormatServie = fileNameFormatServie;
84 | }
85 |
86 | public String getOutPutFullPath() {
87 | if (GeneratorStringUtils.isNotBlank(this.outPutFullPath)){
88 | String collapsePath = new PathUtils('/').collapseFrom(this.outPutFullPath, '/');
89 | return new PathUtils('\\').collapseFrom(collapsePath, '/');
90 | }
91 | return outPutFullPath;
92 | }
93 |
94 | /**
95 | * 设置文件全路径
96 | * @param fileName 文件名
97 | */
98 | public void setOutPutFullPathByFileName(String fileName) {
99 | this.outPutFullPath = MessageFormat.format(getOutPutFullPathFormatPattern(), fileName);
100 | }
101 |
102 | public FileTypeEnums getFileType() {
103 | return fileType;
104 | }
105 |
106 | public void setFileType(FileTypeEnums fileType) {
107 | this.fileType = fileType;
108 | }
109 |
110 | public String getFileNameFormatPattern() {
111 | return fileNameFormatPattern;
112 | }
113 |
114 | public void setFileNameFormatPattern(String fileNameFormatPattern) {
115 | this.fileNameFormatPattern = fileNameFormatPattern;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/vo/GenerateInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.vo;
2 |
3 | import com.github.zhuyizhuo.generator.constants.ConfigConstants;
4 | import com.github.zhuyizhuo.generator.mybatis.convention.ClassCommentInfo;
5 | import com.github.zhuyizhuo.generator.mybatis.dto.JavaClassDefinition;
6 | import com.github.zhuyizhuo.generator.mybatis.dto.MethodDescription;
7 | import com.github.zhuyizhuo.generator.mybatis.dto.JavaColumnInfo;
8 | import com.github.zhuyizhuo.generator.enums.ModuleTypeEnums;
9 | import com.github.zhuyizhuo.generator.mybatis.dto.MybatisXmlDefinition;
10 | import com.github.zhuyizhuo.generator.utils.GeneratorStringUtils;
11 | import com.github.zhuyizhuo.generator.utils.PropertiesUtils;
12 |
13 | import java.util.List;
14 | import java.util.Map;
15 |
16 | /**
17 | * 生成所需元信息
18 | *
19 | * @author zhuo
20 | * @version 1.0
21 | * time: 2018/7/29 17:44
22 | */
23 | public class GenerateInfo {
24 | /** 类注释信息 */
25 | private ClassCommentInfo classCommentInfo;
26 | /** 分层信息 */
27 | private Map
5 | * time: 2019/5/23
6 | *
7 | * @author zhuo
8 | * @since 1.4.0
9 | */
10 | public class ModulePathInfo {
11 | /** 模块类型 */
12 | private String moduleType;
13 | /** 生成文件输出路径 */
14 | private String fileOutputPath;
15 |
16 | public ModulePathInfo(String moduleType, String fileOutputPath) {
17 | this.moduleType = moduleType;
18 | this.fileOutputPath = fileOutputPath;
19 | }
20 |
21 | public String getModuleType() {
22 | return moduleType;
23 | }
24 |
25 | public void setModuleType(String moduleType) {
26 | this.moduleType = moduleType;
27 | }
28 |
29 | public String getFileOutputPath() {
30 | return fileOutputPath;
31 | }
32 |
33 | public void setFileOutputPath(String fileOutputPath) {
34 | this.fileOutputPath = fileOutputPath;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/mybatis/vo/TableInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.mybatis.vo;
2 |
3 | import com.github.zhuyizhuo.generator.mybatis.database.entity.ColumnInfo;
4 | import com.github.zhuyizhuo.generator.mybatis.dto.JavaColumnInfo;
5 | import com.github.zhuyizhuo.generator.utils.GeneratorStringUtils;
6 |
7 | import java.util.ArrayList;
8 | import java.util.LinkedHashSet;
9 | import java.util.List;
10 |
11 | /**
12 | * 生成模板所用对象
13 | * time: 2018/8/3 19:56
14 | *
15 | * @author zhuo
16 | * @version 1.0
17 | */
18 | public class TableInfo {
19 | /** 数据库名称 */
20 | private String tableSchema;
21 | /** 表名 */
22 | private String tableName;
23 | /** 表注释 */
24 | private String tableComment;
25 | /** 表名转驼峰 首字母大写 */
26 | private String tableNameCamelCase;
27 | /** 导入的类路径 */
28 | private LinkedHashSet
11 | * time: 2018/8/20 13:01
12 | *
13 | * @author zhuo
14 | * @since 1.3.0
15 | */
16 | public class CheckUtils {
17 | public static final String[] dbConfig = {ConfigConstants.DB_TYPE,ConfigConstants.URL,ConfigConstants.DRIVER,
18 | ConfigConstants.USERNAME,ConfigConstants.PASSWORD,ConfigConstants.TABLE_SCHEMA};
19 |
20 | public static void assertNotNull(Object moduleType, String errorMsg) throws IllegalArgumentException {
21 | if (moduleType == null){
22 | throw new IllegalArgumentException(errorMsg);
23 | }
24 | }
25 |
26 | public static void assertNotNull(String moduleType, String errorMsg) throws IllegalArgumentException {
27 | if(GeneratorStringUtils.isBlank(moduleType)){
28 | throw new IllegalArgumentException(errorMsg);
29 | }
30 | }
31 |
32 | public static Properties checkDatabaseConfig(Properties properties) throws GeneratorException {
33 | Properties rtnProperties = new Properties();
34 | StringBuffer errorMsg = new StringBuffer();
35 | for (int i = 0; i < dbConfig.length; i++) {
36 | String needProperties = properties.getProperty(dbConfig[i]);
37 | if (GeneratorStringUtils.isBlank(needProperties)){
38 | errorMsg.append("未配置 " + dbConfig[i] + " \n");
39 | } else {
40 | rtnProperties.put(dbConfig[i], needProperties);
41 | }
42 | }
43 | try {
44 | DbTypeEnums.valueOf(properties.getProperty(ConfigConstants.DB_TYPE).toUpperCase());
45 | } catch (Exception e){
46 | DbTypeEnums[] values = DbTypeEnums.values();
47 | errorMsg.append(ConfigConstants.DB_TYPE)
48 | .append(" 配置有误, 支持配置类型:");
49 | for (int i = 0; i < values.length; i++) {
50 | errorMsg.append(values[i].name()).append(" ");
51 | }
52 | }
53 | if (errorMsg.length() > 0){
54 | LogUtils.logProperties("数据库配置信息:", rtnProperties);
55 | throw new GeneratorException(errorMsg.toString());
56 | }
57 | return rtnProperties;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/utils/Freemarker.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.utils;
2 |
3 | import freemarker.template.Configuration;
4 | import freemarker.template.Template;
5 | import freemarker.template.TemplateException;
6 |
7 | import java.io.BufferedWriter;
8 | import java.io.File;
9 | import java.io.FileOutputStream;
10 | import java.io.IOException;
11 | import java.io.OutputStreamWriter;
12 | import java.io.Writer;
13 | import java.util.Locale;
14 |
15 | /**
16 | * freemarker 工具类
17 | * 创建时间:2015年2月8日
18 | * @version 1.0
19 | */
20 | public class Freemarker {
21 |
22 | /**
23 | * 输出对象到文件
24 | * @param ftlFullPath ftl模板路径
25 | * @param outPutPath 输出文件全路径
26 | * @param outPutObject 输出对象
27 | * @throws Exception 获取模板异常抛出
28 | */
29 | public static void printFile(String ftlFullPath, String outPutPath, Object outPutObject) throws Exception{
30 | printFile(GeneratorStringUtils.getFrontPath(ftlFullPath),GeneratorStringUtils.getFileName(ftlFullPath),outPutPath,outPutObject);
31 | }
32 |
33 | /**
34 | * 将root对象输出到文件
35 | * @param ftlPath ftl文件路径
36 | * @param ftlName ftl文件名
37 | * @param outPutPath 输出后的文件全部路径
38 | * @param outPutObject 输出对象
39 | * @throws Exception 获取模板异常抛出
40 | */
41 | public static void printFile(String ftlPath, String ftlName, String outPutPath, Object outPutObject) throws Exception {
42 | try {
43 | File file = new File(outPutPath);
44 | //判断有没有父路径,就是判断文件整个路径是否存在
45 | if(file != null && file.getParentFile() != null && !file.getParentFile().exists()){
46 | //不存在就全部创建
47 | file.getParentFile().mkdirs();
48 | }
49 | Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
50 | Template template = getTemplate(ftlPath, ftlName);
51 | //模版输出
52 | template.process(outPutObject, out);
53 | out.flush();
54 | out.close();
55 | } catch (TemplateException e) {
56 | LogUtils.printException(e);
57 | } catch (IOException e) {
58 | LogUtils.printException(e);
59 | }
60 | }
61 |
62 | /**
63 | * 通过文件名加载模版
64 | * @param ftlPath ftl文件路径
65 | * @param ftlName ftl文件名
66 | * @throws Exception 读取模板失败抛出异常
67 | * @return Template 模板
68 | */
69 | public static Template getTemplate(String ftlPath, String ftlName) throws Exception{
70 | try {
71 | //通过Freemaker的Configuration读取相应的ftl
72 | Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
73 | cfg.setEncoding(Locale.CHINA, "utf-8");
74 | //设定去哪里读取相应的ftl模板文件
75 | cfg.setClassLoaderForTemplateLoading(Freemarker.class.getClassLoader(), ftlPath);
76 | //在模板文件目录中找到名称为name的文件
77 | return cfg.getTemplate(ftlName);
78 | } catch (IOException e) {
79 | LogUtils.printException(e);
80 | }
81 | return null;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/utils/GeneratorStringUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.utils;
2 |
3 | /**
4 | * 字符串工具类
5 | * time: 2018/7/27 11:35
6 | *
7 | * @author zhuo
8 | * @version 1.0
9 | */
10 | public class GeneratorStringUtils {
11 |
12 | /**
13 | * 获取传入文件全路径的路径信息
14 | * @param fileFullpath d:/e/a/1.txt
15 | * @return d:/e/a/
16 | */
17 | public static String getFrontPath(String fileFullpath){
18 | if (isBlank(fileFullpath)){
19 | return "";
20 | }
21 | String fullPath = fileFullpath.replaceAll("\\\\","/");
22 | return fullPath.substring(0,fullPath.lastIndexOf("/") + 1);
23 | }
24 |
25 | /**
26 | * 获取传入文件全路径的文件名称
27 | * @param fileFullpath d:/e/a/1.txt
28 | * @return 1.txt
29 | */
30 | public static String getFileName(String fileFullpath){
31 | if (isBlank(fileFullpath)){
32 | return "";
33 | }
34 | String fullPath = fileFullpath.replaceAll("\\\\","/");
35 | return fullPath.substring(fullPath.lastIndexOf("/") + 1);
36 | }
37 |
38 | /**
39 | *
42 | * GeneratorStringUtils.isBlank(null) = true
43 | * GeneratorStringUtils.isBlank("") = true
44 | * GeneratorStringUtils.isBlank(" ") = true
45 | * GeneratorStringUtils.isBlank("bob") = false
46 | * GeneratorStringUtils.isBlank(" bob ") = false
47 | *
48 | *
49 | * @param cs the CharSequence to check, may be null
50 | * @return {@code true} if the CharSequence is null, empty or whitespace
51 | */
52 | public static boolean isBlank(final CharSequence cs) {
53 | int strLen;
54 | if (cs == null || (strLen = cs.length()) == 0) {
55 | return true;
56 | }
57 | for (int i = 0; i < strLen; i++) {
58 | if (Character.isWhitespace(cs.charAt(i)) == false) {
59 | return false;
60 | }
61 | }
62 | return true;
63 | }
64 |
65 | /**
66 | *
69 | * StringUtils.isNotBlank(null) = false
70 | * StringUtils.isNotBlank("") = false
71 | * StringUtils.isNotBlank(" ") = false
72 | * StringUtils.isNotBlank("bob") = true
73 | * StringUtils.isNotBlank(" bob ") = true
74 | *
75 | *
76 | * @param cs the CharSequence to check, may be null
77 | * @return {@code true} if the CharSequence is
78 | * not empty and not null and not whitespace
79 | */
80 | public static boolean isNotBlank(final CharSequence cs) {
81 | return !isBlank(cs);
82 | }
83 |
84 | /**
85 | * 表名转java驼峰命名(首字母大写)
86 | * @param tableName e.g mybatis_user_info
87 | * @param tableRegex 表名的分隔符 例如 _
88 | * @return MybatisUserInfo
89 | */
90 | public static String changeTableName2CamelFirstUpper(String tableName, String tableRegex) {
91 | String[] split = tableName.split(tableRegex);
92 | StringBuffer s = new StringBuffer();
93 | for (int i = 0; i < split.length; i++) {
94 | s.append(firstUpper(split[i]));
95 | }
96 | return s.toString();
97 | }
98 |
99 | /**
100 | * 数据库字段名转java驼峰命名(驼峰处转大写,其他字母小写) 连接符colmRegex可指定 默认为_
101 | * changeColmName2CamelFirstLower("mybatis_user_info","_") = "mybatisUserInfo"
102 | * changeColmName2CamelFirstLower("MYBATIS_USER_INFO","_") = "mybatisUserInfo"
103 | * @param columnName 列名
104 | * @param colmRegex 字段的分隔符 例如 _
105 | * @return java驼峰命名
106 | */
107 | public static String changeColmName2CamelFirstLower(String columnName, String colmRegex) {
108 | String[] split = columnName.split(colmRegex);
109 | StringBuffer s = new StringBuffer();
110 | char[] charArray = split[0].toCharArray();
111 | for (int i = 0; i < charArray.length; i++) {
112 | s.append(toL(charArray[i]));
113 | }
114 | for (int i = 1; i < split.length; i++) {
115 | s.append(firstUpper(split[i]));
116 | }
117 | return s.toString();
118 | }
119 |
120 | /**
121 | * 首字母大写 其他字母小写
122 | * @param str 传入纯字母字符串
123 | * @return 首字母大写 其他字母小写
124 | */
125 | public static String firstUpper(String str) {
126 | char[] cs = str.toCharArray();
127 | cs[0] = toU(cs[0]);
128 | for (int i = 1; i < cs.length; i++) {
129 | cs[i] = toL(cs[i]);
130 | }
131 | return String.valueOf(cs);
132 | }
133 |
134 | /**
135 | * 首字母小写
136 | * @param str 传入纯字母字符串
137 | * @return 将首字母小写后返回
138 | */
139 | public static String firstLower(String str) {
140 | char[] cs = str.toCharArray();
141 | cs[0] = toL(cs[0]);
142 | return String.valueOf(cs);
143 | }
144 |
145 | /**
146 | * 字母转大写
147 | * @param c a-z
148 | * @return A-Z
149 | */
150 | public static char toU(char c) {
151 | if (c >= 'a' && c <= 'z') {
152 | return (char)(c - 32);
153 | }
154 | return c;
155 | }
156 |
157 | /**
158 | * 字母转小写
159 | * @param c A-Z
160 | * @return a-z
161 | */
162 | public static char toL(char c) {
163 | if (c >= 'A' && c <= 'Z') {
164 | return (char)(c + 32);
165 | }
166 | return c;
167 | }
168 |
169 | }
170 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/utils/LogUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.utils;
2 |
3 | import com.github.zhuyizhuo.generator.enums.LogLevelEnums;
4 | import com.github.zhuyizhuo.generator.mybatis.generator.extension.LogService;
5 | import com.github.zhuyizhuo.generator.mybatis.vo.GenerateInfo;
6 |
7 | import java.util.Properties;
8 |
9 | /**
10 | * 日志输出工具类
11 | * time: 2018/8/6 11:04
12 | *
13 | * @author zhuo
14 | * @version 1.0
15 | */
16 | public class LogUtils {
17 |
18 | private static LogLevelEnums logLevel = LogLevelEnums.INFO;
19 | private static LogService logService;
20 |
21 | /**
22 | * 设置打印日志的 service
23 | * @param logService 日志级别
24 | */
25 | public static void setLogService(LogService logService) {
26 | LogUtils.logService = logService;
27 | }
28 |
29 | /**
30 | * 设置日志级别
31 | * @param level 日志级别
32 | * @since 1.5.1
33 | */
34 | public static void setLevel(LogLevelEnums level) {
35 | LogUtils.logLevel = level;
36 | }
37 |
38 | /**
39 | * 设置日志级别
40 | * @param level 日志级别
41 | * @since 1.5.0
42 | */
43 | public static void setLevel(String level) {
44 | try{
45 | LogUtils.logLevel = LogLevelEnums.valueOf(level);
46 | } catch (Exception e){
47 | LogUtils.logLevel = LogLevelEnums.INFO;
48 | }
49 | }
50 |
51 | /**
52 | * 打印 debug 日志
53 | * @param info 日志内容
54 | */
55 | public static void debug(String info){
56 | if (LogLevelEnums.DEBUG.getLevel() >= getLevel()){
57 | System.out.println(info);
58 | }
59 | }
60 |
61 | /**
62 | * 打印 info 日志
63 | * @param info 日志内容
64 | */
65 | public static void info(String info){
66 | if (LogLevelEnums.INFO.getLevel() >= getLevel()){
67 | System.out.println(info);
68 | }
69 | }
70 |
71 | /**
72 | * 打印错误日志
73 | * @param errorMsg 错误信息
74 | */
75 | public static void error(String errorMsg){
76 | if (LogLevelEnums.INFO.getLevel() >= getLevel()){
77 | System.err.println(errorMsg);
78 | }
79 | }
80 |
81 | /**
82 | * 打印堆栈信息 需要日志级别在 DEBUG 以下
83 | * @param e 异常类
84 | */
85 | public static void printException(Exception e){
86 | if (LogLevelEnums.DEBUG.getLevel() >= getLevel()){
87 | e.printStackTrace();
88 | }
89 | }
90 |
91 | /**
92 | * 打印生成器对象
93 | * @param generateInfo 输出到模板的元数据对象
94 | */
95 | public static void logGenerateInfo(GenerateInfo generateInfo){
96 | if (LogLevelEnums.INFO.getLevel() >= getLevel() && logService != null){
97 | logService.logGenerateInfo(generateInfo);
98 | }
99 | }
100 |
101 | public static void logProperties(String message, Properties properties) {
102 | if (LogLevelEnums.INFO.getLevel() >= getLevel()){
103 | System.out.println(message);
104 | for (String key : properties.stringPropertyNames()) {
105 | System.out.println(key + "=" + properties.getProperty(key));
106 | }
107 | }
108 | }
109 |
110 | public static void debug(String message, Properties properties) {
111 | if (LogLevelEnums.DEBUG.getLevel() >= getLevel()){
112 | System.out.println(message);
113 | for (String key : properties.stringPropertyNames()) {
114 | System.out.println(key + "=" + properties.getProperty(key));
115 | }
116 | }
117 | }
118 |
119 | /**
120 | * 获取日志级别
121 | * @return 当前日志级别
122 | */
123 | private static int getLevel(){
124 | return logLevel.getLevel();
125 | }
126 |
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/utils/PathUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.utils;
2 |
3 | /**
4 | * 路径工具类
5 | *
6 | * @author zhuo
7 | * @since 1.5.0
8 | */
9 | public class PathUtils {
10 |
11 | private final char match;
12 |
13 | public PathUtils(char match) {
14 | this.match = match;
15 | }
16 |
17 | private boolean matches(char c) {
18 | return c == match;
19 | }
20 |
21 | /**
22 | * Returns a string copy of the input character sequence, with each group of consecutive matching
23 | * BMP characters replaced by a single replacement character. For example:
24 | *
25 | * {@code
26 | * CharMatcher.anyOf("eko").collapseFrom("bookkeeper", '-')
27 | * }
28 | *
29 | * ... returns {@code "b-p-r"}.
30 | *
31 | * @param sequence the character sequence to replace matching groups of characters in
32 | * @param replacement the character to append to the result string in place of each group of
33 | * matching characters in {@code sequence}
34 | * @return the new string
35 | */
36 | public String collapseFrom(CharSequence sequence, char replacement) {
37 | // This implementation avoids unnecessary allocation.
38 | int len = sequence.length();
39 | for (int i = 0; i < len; i++) {
40 | char c = sequence.charAt(i);
41 | if (matches(c)) {
42 | if (c == replacement && (i == len - 1 || !matches(sequence.charAt(i + 1)))) {
43 | // a no-op replacement
44 | i++;
45 | } else {
46 | StringBuilder builder = new StringBuilder(len).append(sequence, 0, i).append(replacement);
47 | return finishCollapseFrom(sequence, i + 1, len, replacement, builder, true);
48 | }
49 | }
50 | }
51 | // no replacement needed
52 | return sequence.toString();
53 | }
54 |
55 | private String finishCollapseFrom(
56 | CharSequence sequence,
57 | int start,
58 | int end,
59 | char replacement,
60 | StringBuilder builder,
61 | boolean inMatchingGroup) {
62 | for (int i = start; i < end; i++) {
63 | char c = sequence.charAt(i);
64 | if (matches(c)) {
65 | if (!inMatchingGroup) {
66 | builder.append(replacement);
67 | inMatchingGroup = true;
68 | }
69 | } else {
70 | builder.append(c);
71 | inMatchingGroup = false;
72 | }
73 | }
74 | return builder.toString();
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/utils/PropertiesUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.utils;
2 |
3 | import com.github.zhuyizhuo.generator.exception.GeneratorException;
4 | import com.github.zhuyizhuo.generator.mybatis.generator.support.ContextHolder;
5 | import org.apache.ibatis.io.Resources;
6 |
7 | import java.io.BufferedReader;
8 | import java.io.InputStreamReader;
9 | import java.nio.charset.StandardCharsets;
10 | import java.util.Properties;
11 |
12 | /**
13 | * 资源文件处理工具类
14 | * @author zhuo
15 | * @version 1.0
16 | * time: 2018/7/29 18:39
17 | */
18 | public class PropertiesUtils {
19 | /** 自定义配置 */
20 | public static final Properties customConfiguration = new Properties();
21 |
22 | /**
23 | * 加载配置文件
24 | * @param configPath 配置文件路径
25 | */
26 | public static Properties loadProperties(String configPath) throws GeneratorException {
27 | try {
28 | if (GeneratorStringUtils.isBlank(configPath)) {
29 | return customConfiguration;
30 | }
31 | return loadProperties(new BufferedReader(new InputStreamReader(Resources.getResourceAsStream(configPath), StandardCharsets.UTF_8)));
32 | } catch (Exception e){
33 | LogUtils.printException(e);
34 | throw new GeneratorException("加载配置文件失败,path:" + configPath+",Exception:" + e.getMessage());
35 | }
36 | }
37 |
38 | /**
39 | * 加载配置文件
40 | */
41 | public static Properties loadProperties(BufferedReader resourceAsStream) {
42 | try {
43 | customConfiguration.load(resourceAsStream);
44 | return customConfiguration;
45 | } catch (Exception e) {
46 | LogUtils.printException(e);
47 | throw new GeneratorException("加载配置文件失败!");
48 | }
49 | }
50 |
51 | public static String getProperties(String key){
52 | String property = customConfiguration.getProperty(key);
53 | return property == null ? null : property.trim();
54 | }
55 |
56 | /**
57 | * 获取配置信息
58 | * @param key 键
59 | * @return 不存在或配置有误 返回 FALSE
60 | */
61 | public static boolean getBooleanConfigDefaultFalse(String key){
62 | try {
63 | return Boolean.parseBoolean(ContextHolder.getConfig(key));
64 | } catch(Exception e) {
65 | LogUtils.info("key:"+key+" 配置有误,有效值为 true 或 false!");
66 | return false;
67 | }
68 | }
69 |
70 | /**
71 | * 获取配置信息
72 | * @param key 键
73 | * @return 不存在则 返回TRUE
74 | */
75 | public static boolean getBooleanConfigDefaultTrue(String key){
76 | try {
77 | return Boolean.parseBoolean(ContextHolder.getConfig(key));
78 | } catch(Exception e) {
79 | LogUtils.info("key:"+key+" 配置有误,有效值为 true 或 false!");
80 | return true;
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/utils/SqlSessionUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.utils;
2 |
3 | import org.apache.ibatis.io.Resources;
4 | import org.apache.ibatis.session.SqlSession;
5 | import org.apache.ibatis.session.SqlSessionFactory;
6 | import org.apache.ibatis.session.SqlSessionFactoryBuilder;
7 |
8 | import java.io.InputStream;
9 |
10 | /**
11 | * 获取 SqlSession
12 | * time: 2018/7/30 12:34
13 | *
14 | * @author zhuo
15 | * @version 1.0
16 | */
17 | public class SqlSessionUtils {
18 |
19 | /**
20 | * 相对路径加载配置文件
21 | * @return SqlSession instance
22 | */
23 | public static SqlSession getSqlSession() throws RuntimeException {
24 | try {
25 | //配置文件
26 | String resource = "mybatis/mybatis-config.xml";
27 | InputStream inputStream = Resources.getResourceAsStream(resource);
28 | SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream, PropertiesUtils.customConfiguration);
29 | return sqlSessionFactory.openSession();
30 | } catch (Exception e){
31 | throw new RuntimeException("SqlSessionUtils.getSqlSession Exception",e);
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/github/zhuyizhuo/generator/utils/TypeConversion.java:
--------------------------------------------------------------------------------
1 | package com.github.zhuyizhuo.generator.utils;
2 |
3 | import com.github.zhuyizhuo.generator.enums.ErrorTypeEnums;
4 | import org.apache.ibatis.type.JdbcType;
5 |
6 | import java.math.BigDecimal;
7 | import java.time.LocalDateTime;
8 | import java.util.HashMap;
9 | import java.util.Map;
10 | import java.util.Objects;
11 |
12 | /**
13 | *
3 | <#list methodDescription.BATCH_INSERT.params as param>
4 | * @param ${javaClassDefinition.MODEL.className?uncap_first}List ${param.comment}
5 | #list>
6 | * @return 新增的数据条数
7 | */
8 | int ${methodDescription.BATCH_INSERT.methodName}(List<${javaClassDefinition.MODEL.className}> ${javaClassDefinition.MODEL.className?uncap_first}List);
9 |
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/common/countByWhere.ftl:
--------------------------------------------------------------------------------
1 | /**
2 | * ${methodDescription.COUNT_BY_WHERE.comment}
3 | <#list methodDescription.COUNT_BY_WHERE.params as param>
4 | * @param ${javaClassDefinition.MODEL.className?uncap_first} ${param.comment}
5 | #list>
6 | * @return 符合条件的数据总数
7 | */
8 | int ${methodDescription.COUNT_BY_WHERE.methodName}(${javaClassDefinition.MODEL.className} ${javaClassDefinition.MODEL.className?uncap_first});
9 |
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/common/deleteByPrimaryKey.ftl:
--------------------------------------------------------------------------------
1 | <#if tableInfo.singlePrimaryKey>
2 | /**
3 | * ${methodDescription.DELETE_BY_PRIMARY_KEY.comment}
4 | * @param ${tableInfo.primaryKeyColumns[0].javaColumnName?uncap_first} ${tableInfo.primaryKeyColumns[0].columnComment}
5 | * @return 删除的数据条数
6 | */
7 | int ${methodDescription.DELETE_BY_PRIMARY_KEY.methodName}(${tableInfo.primaryKeyColumns[0].javaDataType} ${tableInfo.primaryKeyColumns[0].javaColumnName?uncap_first});
8 | <#else>
9 | /**
10 | * ${methodDescription.DELETE_BY_PRIMARY_KEY.comment}
11 | <#list methodDescription.DELETE_BY_PRIMARY_KEY.params as param>
12 | * @param ${javaClassDefinition.MODEL.className?uncap_first} ${param.comment}
13 | #list>
14 | * @return 删除的数据条数
15 | */
16 | int ${methodDescription.DELETE_BY_PRIMARY_KEY.methodName}(${javaClassDefinition.MODEL.className} ${javaClassDefinition.MODEL.className?uncap_first});
17 | #if>
18 |
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/common/deleteByWhere.ftl:
--------------------------------------------------------------------------------
1 | /**
2 | * ${methodDescription.DELETE_BY_WHERE.comment}
3 | <#list methodDescription.DELETE_BY_WHERE.params as param>
4 | * @param ${javaClassDefinition.MODEL.className?uncap_first} ${param.comment}
5 | #list>
6 | * @return 删除的数据条数
7 | */
8 | int ${methodDescription.DELETE_BY_WHERE.methodName}(${javaClassDefinition.MODEL.className} ${javaClassDefinition.MODEL.className?uncap_first});
9 |
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/common/insert.ftl:
--------------------------------------------------------------------------------
1 | /**
2 | * ${methodDescription.INSERT.comment}
3 | <#list methodDescription.INSERT.params as param>
4 | * @param ${javaClassDefinition.MODEL.className?uncap_first} ${param.comment}
5 | #list>
6 | * @return 新增的数据条数
7 | */
8 | int ${methodDescription.INSERT.methodName}(${javaClassDefinition.MODEL.className} ${javaClassDefinition.MODEL.className?uncap_first});
9 |
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/common/model.ftl:
--------------------------------------------------------------------------------
1 | package ${javaClassDefinition.MODEL.fullPackage};
2 |
3 | <#list tableInfo.importPackages as import>
4 | <#if import??>
5 | import ${import};
6 | #if>
7 | #list>
8 |
9 | /**
10 | * ${tableInfo.tableComment!}
11 | *
12 | * @author ${classCommentInfo.author}
13 | * @date ${classCommentInfo.createTime}
14 | * @since ${classCommentInfo.sinceVersion}
15 | */
16 | public class ${javaClassDefinition.MODEL.className} {
17 |
18 | <#list tableInfo.columnLists as colm>
19 | <#if colm??>
20 | /** ${colm.columnComment} */
21 | private ${colm.javaDataType} ${colm.javaColumnName};
22 | #if>
23 | #list>
24 |
25 | <#list tableInfo.columnLists as colm>
26 | <#if colm??>
27 | public ${colm.javaDataType} get${colm.javaColumnName?cap_first}() {
28 | return ${colm.javaColumnName};
29 | }
30 |
31 | public void set${colm.javaColumnName?cap_first}(${colm.javaDataType} ${colm.javaColumnName}) {
32 | this.${colm.javaColumnName} = ${colm.javaColumnName};
33 | }
34 |
35 | #if>
36 | #list>
37 | }
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/common/model_lombok.ftl:
--------------------------------------------------------------------------------
1 | package ${javaClassDefinition.MODEL.fullPackage};
2 |
3 | import lombok.Data;
4 |
5 | <#list tableInfo.importPackages as import>
6 | <#if import??>
7 | import ${import};
8 | #if>
9 | #list>
10 |
11 | /**
12 | * ${tableInfo.tableComment!}
13 | *
14 | * @author ${classCommentInfo.author}
15 | * @date ${classCommentInfo.createTime}
16 | * @since ${classCommentInfo.sinceVersion}
17 | */
18 | @Data
19 | public class ${javaClassDefinition.MODEL.className} {
20 |
21 | <#list tableInfo.columnLists as colm>
22 | <#if colm??>
23 | /** ${colm.columnComment} */
24 | private ${colm.javaDataType} ${colm.javaColumnName};
25 | #if>
26 | #list>
27 |
28 | }
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/common/queryByPrimaryKey.ftl:
--------------------------------------------------------------------------------
1 | <#if tableInfo.singlePrimaryKey>
2 | /**
3 | * ${methodDescription.QUERY_BY_PRIMARY_KEY.comment}
4 | * @param ${tableInfo.primaryKeyColumns[0].javaColumnName?uncap_first} ${tableInfo.primaryKeyColumns[0].columnComment}
5 | * @return ${javaClassDefinition.MODEL.className} 数据对象
6 | */
7 | ${javaClassDefinition.MODEL.className} ${methodDescription.QUERY_BY_PRIMARY_KEY.methodName}(${tableInfo.primaryKeyColumns[0].javaDataType} ${tableInfo.primaryKeyColumns[0].javaColumnName?uncap_first});
8 | <#else>
9 | /**
10 | * ${methodDescription.QUERY_BY_PRIMARY_KEY.comment}
11 | <#list methodDescription.QUERY_BY_PRIMARY_KEY.params as param>
12 | * @param ${javaClassDefinition.MODEL.className?uncap_first} ${param.comment}
13 | #list>
14 | * @return ${javaClassDefinition.MODEL.className} 数据对象
15 | */
16 | ${javaClassDefinition.MODEL.className} ${methodDescription.QUERY_BY_PRIMARY_KEY.methodName}(${javaClassDefinition.MODEL.className} ${javaClassDefinition.MODEL.className?uncap_first});
17 | #if>
18 |
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/common/queryByWhere.ftl:
--------------------------------------------------------------------------------
1 | /**
2 | * ${methodDescription.QUERY_BY_WHERE.comment}
3 | <#list methodDescription.QUERY_BY_WHERE.params as param>
4 | * @param ${javaClassDefinition.MODEL.className?uncap_first} ${param.comment}
5 | #list>
6 | * @return 符合条件的数据集合
7 | */
8 | List<${javaClassDefinition.MODEL.className}> ${methodDescription.QUERY_BY_WHERE.methodName}(${javaClassDefinition.MODEL.className} ${javaClassDefinition.MODEL.className?uncap_first});
9 |
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/common/updateByPrimaryKey.ftl:
--------------------------------------------------------------------------------
1 | /**
2 | * ${methodDescription.UPDATE_BY_PRIMARY_KEY.comment}
3 | <#list methodDescription.UPDATE_BY_PRIMARY_KEY.params as param>
4 | * @param ${javaClassDefinition.MODEL.className?uncap_first} ${param.comment}
5 | #list>
6 | * @return 更新的数据条数
7 | */
8 | int ${methodDescription.UPDATE_BY_PRIMARY_KEY.methodName}(${javaClassDefinition.MODEL.className} ${javaClassDefinition.MODEL.className?uncap_first});
9 |
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/common/vo_swagger_lombok.ftl:
--------------------------------------------------------------------------------
1 | package ${javaClassDefinition.VO.fullPackage};
2 |
3 | import io.swagger.annotations.ApiModelProperty;
4 | import lombok.Data;
5 |
6 | import java.io.Serializable;
7 | <#list tableInfo.importPackages as import>
8 | <#if import??>
9 | import ${import};
10 | #if>
11 | #list>
12 |
13 | /**
14 | * ${tableInfo.tableComment!}
15 | *
16 | * @author ${classCommentInfo.author}
17 | * @date ${classCommentInfo.createTime}
18 | * @since ${classCommentInfo.sinceVersion}
19 | */
20 | @Data
21 | public class ${javaClassDefinition.VO.className} implements Serializable {
22 | private static final long serialVersionUID=1L;
23 |
24 | <#list tableInfo.columnLists as colm>
25 | <#if colm??>
26 | /** ${colm.columnComment} */
27 | @ApiModelProperty(value = "${colm.columnComment}")
28 | private ${colm.javaDataType} ${colm.javaColumnName};
29 | #if>
30 | #list>
31 |
32 | }
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/mybatis_plus/mapper_mybatis_plus.ftl:
--------------------------------------------------------------------------------
1 | package ${javaClassDefinition.MAPPER.fullPackage};
2 |
3 |
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import ${javaClassDefinition.MODEL.fullPackage}.${javaClassDefinition.MODEL.className};
6 | import org.apache.ibatis.annotations.Mapper;
7 |
8 | /**
9 | * ${tableInfo.tableComment!} Mapper
10 | *
11 | * @author ${classCommentInfo.author}
12 | * @date ${classCommentInfo.createTime}
13 | * @since ${classCommentInfo.sinceVersion}
14 | */
15 | @Mapper
16 | public interface ${javaClassDefinition.MAPPER.className} extends BaseMapper<${javaClassDefinition.MODEL.className}> {
17 |
18 | }
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/mybatis_plus/model_mybatis_plus.ftl:
--------------------------------------------------------------------------------
1 | package ${javaClassDefinition.MODEL.fullPackage};
2 |
3 | import com.baomidou.mybatisplus.annotation.TableId;
4 | import com.baomidou.mybatisplus.annotation.TableName;
5 |
6 | import java.io.Serializable;
7 | <#list tableInfo.importPackages as import>
8 | <#if import??>
9 | import ${import};
10 | #if>
11 | #list>
12 |
13 | /**
14 | * ${tableInfo.tableComment!}
15 | *
16 | * @author ${classCommentInfo.author}
17 | * @date ${classCommentInfo.createTime}
18 | * @since ${classCommentInfo.sinceVersion}
19 | */
20 | @TableName("${tableInfo.tableName}")
21 | public class ${javaClassDefinition.MODEL.className} implements Serializable {
22 | private static final long serialVersionUID=1L;
23 | <#list tableInfo.primaryKeyColumns as colm>
24 | <#if colm??>
25 | /** ${colm.columnComment} */
26 | @TableId
27 | private ${colm.javaDataType} ${colm.javaColumnName};
28 | #if>
29 | #list>
30 | <#list tableInfo.columnLists as colm>
31 | <#if colm??>
32 | <#if (colm_index >= tableInfo.primaryKeyColumns?size)>
33 | /** ${colm.columnComment} */
34 | private ${colm.javaDataType} ${colm.javaColumnName};
35 | #if>
36 | #if>
37 | #list>
38 |
39 | <#list tableInfo.columnLists as colm>
40 | <#if colm??>
41 | public ${colm.javaDataType} get${colm.javaColumnName?cap_first}() {
42 | return ${colm.javaColumnName};
43 | }
44 |
45 | public void set${colm.javaColumnName?cap_first}(${colm.javaDataType} ${colm.javaColumnName}) {
46 | this.${colm.javaColumnName} = ${colm.javaColumnName};
47 | }
48 |
49 | #if>
50 | #list>
51 | }
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/mybatis_plus/model_mybatis_plus_lombok.ftl:
--------------------------------------------------------------------------------
1 | package ${javaClassDefinition.MODEL.fullPackage};
2 |
3 | import com.baomidou.mybatisplus.annotation.TableId;
4 | import com.baomidou.mybatisplus.annotation.TableName;
5 | import lombok.Data;
6 |
7 | import java.io.Serializable;
8 | <#list tableInfo.importPackages as import>
9 | <#if import??>
10 | import ${import};
11 | #if>
12 | #list>
13 |
14 | /**
15 | * ${tableInfo.tableComment}
16 | *
17 | * @author ${classCommentInfo.author}
18 | * @since ${classCommentInfo.sinceVersion}
19 | */
20 | @Data
21 | @TableName("${tableInfo.tableName}")
22 | public class ${javaClassDefinition.MODEL.className} implements Serializable {
23 | private static final long serialVersionUID=1L;
24 | <#list tableInfo.primaryKeyColumns as colm>
25 | <#if colm??>
26 | /** ${colm.columnComment} */
27 | @TableId
28 | private ${colm.javaDataType} ${colm.javaColumnName};
29 | #if>
30 | #list>
31 | <#list tableInfo.columnLists as colm>
32 | <#if colm??>
33 | <#if (colm_index >= tableInfo.primaryKeyColumns?size)>
34 | /** ${colm.columnComment} */
35 | private ${colm.javaDataType} ${colm.javaColumnName};
36 | #if>
37 | #if>
38 | #list>
39 |
40 | }
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/mybatis_plus/service_impl_mybatis_plus.ftl:
--------------------------------------------------------------------------------
1 | package ${javaClassDefinition.SERVICE_IMPL.fullPackage};
2 |
3 | import org.springframework.stereotype.Service;
4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5 |
6 | import ${javaClassDefinition.MAPPER.fullPackage}.${javaClassDefinition.MAPPER.className};
7 | import ${javaClassDefinition.MODEL.fullPackage}.${javaClassDefinition.MODEL.className};
8 | import ${javaClassDefinition.SERVICE.fullPackage}.${javaClassDefinition.SERVICE.className};
9 |
10 | /**
11 | * ${tableInfo.tableComment!} Service 实现类
12 | *
13 | * @author ${classCommentInfo.author}
14 | * @date ${classCommentInfo.createTime}
15 | * @since ${classCommentInfo.sinceVersion}
16 | */
17 | @Service("${javaClassDefinition.SERVICE_IMPL.className?uncap_first}")
18 | public class ${javaClassDefinition.SERVICE_IMPL.className} extends ServiceImpl<${javaClassDefinition.MAPPER.className}, ${javaClassDefinition.MODEL.className}> implements ${javaClassDefinition.SERVICE.className} {
19 |
20 | }
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/mybatis_plus/service_mybatis_plus.ftl:
--------------------------------------------------------------------------------
1 | package ${javaClassDefinition.SERVICE.fullPackage};
2 |
3 | import com.baomidou.mybatisplus.extension.service.IService;
4 | import ${javaClassDefinition.MODEL.fullPackage}.${javaClassDefinition.MODEL.className};
5 |
6 | /**
7 | * ${tableInfo.tableComment!} Service
8 | *
9 | * @author ${classCommentInfo.author}
10 | * @date ${classCommentInfo.createTime}
11 | * @since ${classCommentInfo.sinceVersion}
12 | */
13 | public interface ${javaClassDefinition.SERVICE.className} extends IService<${javaClassDefinition.MODEL.className}> {
14 |
15 | }
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/mybatis_plus/xml_mybatis_plus.ftl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 | *
10 | * @author ${classCommentInfo.author}
11 | * @date ${classCommentInfo.createTime}
12 | * @since ${classCommentInfo.sinceVersion}
13 | */
14 | public interface ${javaClassDefinition.MAPPER.className} {
15 | <#if methodDescription.INSERT.enabled>
16 |
17 | <#include "common/insert.ftl"/>
18 | #if>
19 | <#if methodDescription.DELETE_BY_WHERE.enabled>
20 |
21 | <#include "common/deleteByWhere.ftl"/>
22 | #if>
23 | <#if methodDescription.QUERY_BY_WHERE.enabled>
24 |
25 | <#include "common/queryByWhere.ftl"/>
26 | #if>
27 | <#if methodDescription.COUNT_BY_WHERE.enabled>
28 |
29 | <#include "common/countByWhere.ftl"/>
30 | #if>
31 | <#if methodDescription.BATCH_INSERT.enabled>
32 |
33 | <#include "common/batchInsert.ftl"/>
34 | #if>
35 | }
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/no_primary_key_oracle_mapper_template.ftl:
--------------------------------------------------------------------------------
1 | package ${javaClassDefinition.MAPPER.fullPackage};
2 |
3 | import java.util.List;
4 |
5 | import ${javaClassDefinition.MODEL.fullPackage}.${javaClassDefinition.MODEL.className};
6 |
7 | /**
8 | * ${tableInfo.tableComment!} dao layer interface
9 | *
10 | * @author ${classCommentInfo.author}
11 | * @date ${classCommentInfo.createTime}
12 | * @since ${classCommentInfo.sinceVersion}
13 | */
14 | public interface ${javaClassDefinition.MAPPER.className} {
15 | <#if methodDescription.INSERT.enabled>
16 |
17 | <#include "common/insert.ftl"/>
18 | #if>
19 | <#if methodDescription.DELETE_BY_WHERE.enabled>
20 |
21 | <#include "common/deleteByWhere.ftl"/>
22 | #if>
23 | <#if methodDescription.QUERY_BY_WHERE.enabled>
24 |
25 | <#include "common/queryByWhere.ftl"/>
26 | #if>
27 | <#if methodDescription.COUNT_BY_WHERE.enabled>
28 |
29 | <#include "common/countByWhere.ftl"/>
30 | #if>
31 | <#if methodDescription.BATCH_INSERT.enabled>
32 |
33 | <#include "common/batchInsert.ftl"/>
34 | #if>
35 | }
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/primary_key_mysql_mapper_template.ftl:
--------------------------------------------------------------------------------
1 | package ${javaClassDefinition.MAPPER.fullPackage};
2 |
3 | import java.util.List;
4 |
5 | import ${javaClassDefinition.MODEL.fullPackage}.${javaClassDefinition.MODEL.className};
6 |
7 | /**
8 | * ${tableInfo.tableComment!} dao layer interface
9 | *
10 | * @author ${classCommentInfo.author}
11 | * @date ${classCommentInfo.createTime}
12 | * @since ${classCommentInfo.sinceVersion}
13 | */
14 | public interface ${javaClassDefinition.MAPPER.className} {
15 | <#if methodDescription.INSERT.enabled>
16 |
17 | <#include "common/insert.ftl"/>
18 | #if>
19 | <#if methodDescription.DELETE_BY_PRIMARY_KEY.enabled>
20 |
21 | <#include "common/deleteByPrimaryKey.ftl"/>
22 | #if>
23 | <#if methodDescription.DELETE_BY_WHERE.enabled>
24 |
25 | <#include "common/deleteByWhere.ftl"/>
26 | #if>
27 | <#if methodDescription.UPDATE_BY_PRIMARY_KEY.enabled>
28 |
29 | <#include "common/updateByPrimaryKey.ftl"/>
30 | #if>
31 | <#if methodDescription.QUERY_BY_PRIMARY_KEY.enabled>
32 |
33 | <#include "common/queryByPrimaryKey.ftl"/>
34 | #if>
35 | <#if methodDescription.QUERY_BY_WHERE.enabled>
36 |
37 | <#include "common/queryByWhere.ftl"/>
38 | #if>
39 | <#if methodDescription.COUNT_BY_WHERE.enabled>
40 |
41 | <#include "common/countByWhere.ftl"/>
42 | #if>
43 | <#if methodDescription.BATCH_INSERT.enabled>
44 |
45 | <#include "common/batchInsert.ftl"/>
46 | #if>
47 | }
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/java/primary_key_oracle_mapper_template.ftl:
--------------------------------------------------------------------------------
1 | package ${javaClassDefinition.MAPPER.fullPackage};
2 |
3 | import java.util.List;
4 |
5 | import ${javaClassDefinition.MODEL.fullPackage}.${javaClassDefinition.MODEL.className};
6 |
7 | /**
8 | * ${tableInfo.tableComment!} dao layer interface
9 | *
10 | * @author ${classCommentInfo.author}
11 | * @date ${classCommentInfo.createTime}
12 | * @since ${classCommentInfo.sinceVersion}
13 | */
14 | public interface ${javaClassDefinition.MAPPER.className} {
15 | <#if methodDescription.INSERT.enabled>
16 |
17 | <#include "common/insert.ftl"/>
18 | #if>
19 | <#if methodDescription.DELETE_BY_PRIMARY_KEY.enabled>
20 |
21 | <#include "common/deleteByPrimaryKey.ftl"/>
22 | #if>
23 | <#if methodDescription.DELETE_BY_WHERE.enabled>
24 |
25 | <#include "common/deleteByWhere.ftl"/>
26 | #if>
27 | <#if methodDescription.UPDATE_BY_PRIMARY_KEY.enabled>
28 |
29 | <#include "common/updateByPrimaryKey.ftl"/>
30 | #if>
31 | <#if methodDescription.QUERY_BY_PRIMARY_KEY.enabled>
32 |
33 | <#include "common/queryByPrimaryKey.ftl"/>
34 | #if>
35 | <#if methodDescription.QUERY_BY_WHERE.enabled>
36 |
37 | <#include "common/queryByWhere.ftl"/>
38 | #if>
39 | <#if methodDescription.COUNT_BY_WHERE.enabled>
40 |
41 | <#include "common/countByWhere.ftl"/>
42 | #if>
43 | <#if methodDescription.BATCH_INSERT.enabled>
44 |
45 | <#include "common/batchInsert.ftl"/>
46 | #if>
47 | }
--------------------------------------------------------------------------------
/src/main/resources/freemarker/template/xml/common/common_sql_xml.ftl:
--------------------------------------------------------------------------------
1 |