Commit 28ae4887f006ea120a4e1809d93281254eab12ea
1 parent
ffbad1ce
Exists in
master
add generate cover method
Showing
3 changed files
with
72 additions
and
37 deletions
Show diff stats
build.gradle
@@ -51,7 +51,7 @@ uploadArchives { | @@ -51,7 +51,7 @@ uploadArchives { | ||
51 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) | 51 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) |
52 | } | 52 | } |
53 | pom.project { | 53 | pom.project { |
54 | - version '1.2.10' | 54 | + version '1.2.11' |
55 | artifactId ARTIFACT_Id | 55 | artifactId ARTIFACT_Id |
56 | groupId GROUP_ID | 56 | groupId GROUP_ID |
57 | packaging TYPE | 57 | packaging TYPE |
build/classes/java/main/com/taover/codegenerate/bazhuayun/GenerateCode.class
No preview for this file type
src/main/java/com/taover/codegenerate/bazhuayun/GenerateCode.java
@@ -21,7 +21,7 @@ import freemarker.template.Template; | @@ -21,7 +21,7 @@ import freemarker.template.Template; | ||
21 | public class GenerateCode { | 21 | public class GenerateCode { |
22 | public static void main(String args[]){ | 22 | public static void main(String args[]){ |
23 | try { | 23 | try { |
24 | - generateEntity("com.taover.wxorder", "ecs_shippings_regions", "D:"+File.separator+"dblist", "127.0.0.1", "3306", "tylife", "lexi365", "tylife"); | 24 | + generateEntity("com.taover.wxorder", "ecs_shippings_regions", "D:"+File.separator+"dblist", "127.0.0.1", "3306", "tylife", "lexi365", "tylife", false); |
25 | } catch (Exception e) { | 25 | } catch (Exception e) { |
26 | e.printStackTrace(); | 26 | e.printStackTrace(); |
27 | } | 27 | } |
@@ -63,19 +63,20 @@ public class GenerateCode { | @@ -63,19 +63,20 @@ public class GenerateCode { | ||
63 | continue; | 63 | continue; |
64 | } | 64 | } |
65 | 65 | ||
66 | + boolean isCover = false; | ||
66 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); | 67 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); |
67 | //generateDto(srcPath, apiModel); | 68 | //generateDto(srcPath, apiModel); |
68 | - generateEntity(srcPath, apiModel); | ||
69 | - generateManageController(srcPath, apiModel); | ||
70 | - generateV1Controller(srcPath, apiModel); | ||
71 | - generateRepository(srcPath, apiModel); | ||
72 | - generateService(srcPath, apiModel); | ||
73 | - //generateVo(srcPath, apiModel); | 69 | + generateEntity(srcPath, apiModel, isCover); |
70 | + generateManageController(srcPath, apiModel, isCover); | ||
71 | + generateV1Controller(srcPath, apiModel, isCover); | ||
72 | + generateRepository(srcPath, apiModel, isCover); | ||
73 | + generateService(srcPath, apiModel, isCover); | ||
74 | + generateVo(srcPath, apiModel, isCover); | ||
74 | } | 75 | } |
75 | System.out.println("处理完成"); | 76 | System.out.println("处理完成"); |
76 | } | 77 | } |
77 | 78 | ||
78 | - public static void generateDto(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName) throws Exception{ | 79 | + public static void generateCoverWhenFileExists(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName) throws Exception{ |
79 | //取数据库连接 | 80 | //取数据库连接 |
80 | Connection conn = getConnection(host, port, user, password, dbName); | 81 | Connection conn = getConnection(host, port, user, password, dbName); |
81 | //初始化要生成的表列表 | 82 | //初始化要生成的表列表 |
@@ -97,12 +98,19 @@ public class GenerateCode { | @@ -97,12 +98,19 @@ public class GenerateCode { | ||
97 | } | 98 | } |
98 | 99 | ||
99 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); | 100 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); |
100 | - generateDto(srcPath, apiModel); | 101 | + boolean isCover = true; |
102 | + //generateDto(srcPath, apiModel); | ||
103 | + generateEntity(srcPath, apiModel, isCover); | ||
104 | + generateManageController(srcPath, apiModel, isCover); | ||
105 | + generateV1Controller(srcPath, apiModel, isCover); | ||
106 | + generateRepository(srcPath, apiModel, isCover); | ||
107 | + generateService(srcPath, apiModel, isCover); | ||
108 | + generateVo(srcPath, apiModel, isCover); | ||
101 | } | 109 | } |
102 | System.out.println("处理完成"); | 110 | System.out.println("处理完成"); |
103 | } | 111 | } |
104 | 112 | ||
105 | - public static void generateEntity(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName) throws Exception{ | 113 | + public static void generateDto(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName, boolean isCover) throws Exception{ |
106 | //取数据库连接 | 114 | //取数据库连接 |
107 | Connection conn = getConnection(host, port, user, password, dbName); | 115 | Connection conn = getConnection(host, port, user, password, dbName); |
108 | //初始化要生成的表列表 | 116 | //初始化要生成的表列表 |
@@ -124,12 +132,12 @@ public class GenerateCode { | @@ -124,12 +132,12 @@ public class GenerateCode { | ||
124 | } | 132 | } |
125 | 133 | ||
126 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); | 134 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); |
127 | - generateEntity(srcPath, apiModel); | 135 | + generateDto(srcPath, apiModel, isCover); |
128 | } | 136 | } |
129 | System.out.println("处理完成"); | 137 | System.out.println("处理完成"); |
130 | } | 138 | } |
131 | 139 | ||
132 | - public static void generateControllerManage(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName) throws Exception{ | 140 | + public static void generateEntity(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName, boolean isCover) throws Exception{ |
133 | //取数据库连接 | 141 | //取数据库连接 |
134 | Connection conn = getConnection(host, port, user, password, dbName); | 142 | Connection conn = getConnection(host, port, user, password, dbName); |
135 | //初始化要生成的表列表 | 143 | //初始化要生成的表列表 |
@@ -151,12 +159,12 @@ public class GenerateCode { | @@ -151,12 +159,12 @@ public class GenerateCode { | ||
151 | } | 159 | } |
152 | 160 | ||
153 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); | 161 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); |
154 | - generateManageController(srcPath, apiModel); | 162 | + generateEntity(srcPath, apiModel, isCover); |
155 | } | 163 | } |
156 | System.out.println("处理完成"); | 164 | System.out.println("处理完成"); |
157 | } | 165 | } |
158 | 166 | ||
159 | - public static void generateControllerV1(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName) throws Exception{ | 167 | + public static void generateControllerManage(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName, boolean isCover) throws Exception{ |
160 | //取数据库连接 | 168 | //取数据库连接 |
161 | Connection conn = getConnection(host, port, user, password, dbName); | 169 | Connection conn = getConnection(host, port, user, password, dbName); |
162 | //初始化要生成的表列表 | 170 | //初始化要生成的表列表 |
@@ -178,12 +186,12 @@ public class GenerateCode { | @@ -178,12 +186,12 @@ public class GenerateCode { | ||
178 | } | 186 | } |
179 | 187 | ||
180 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); | 188 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); |
181 | - generateV1Controller(srcPath, apiModel); | 189 | + generateManageController(srcPath, apiModel, isCover); |
182 | } | 190 | } |
183 | System.out.println("处理完成"); | 191 | System.out.println("处理完成"); |
184 | } | 192 | } |
185 | 193 | ||
186 | - public static void generateRepository(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName) throws Exception{ | 194 | + public static void generateControllerV1(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName, boolean isCover) throws Exception{ |
187 | //取数据库连接 | 195 | //取数据库连接 |
188 | Connection conn = getConnection(host, port, user, password, dbName); | 196 | Connection conn = getConnection(host, port, user, password, dbName); |
189 | //初始化要生成的表列表 | 197 | //初始化要生成的表列表 |
@@ -205,12 +213,12 @@ public class GenerateCode { | @@ -205,12 +213,12 @@ public class GenerateCode { | ||
205 | } | 213 | } |
206 | 214 | ||
207 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); | 215 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); |
208 | - generateRepository(srcPath, apiModel); | 216 | + generateV1Controller(srcPath, apiModel, isCover); |
209 | } | 217 | } |
210 | System.out.println("处理完成"); | 218 | System.out.println("处理完成"); |
211 | } | 219 | } |
212 | 220 | ||
213 | - public static void generateService(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName) throws Exception{ | 221 | + public static void generateRepository(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName, boolean isCover) throws Exception{ |
214 | //取数据库连接 | 222 | //取数据库连接 |
215 | Connection conn = getConnection(host, port, user, password, dbName); | 223 | Connection conn = getConnection(host, port, user, password, dbName); |
216 | //初始化要生成的表列表 | 224 | //初始化要生成的表列表 |
@@ -232,12 +240,12 @@ public class GenerateCode { | @@ -232,12 +240,12 @@ public class GenerateCode { | ||
232 | } | 240 | } |
233 | 241 | ||
234 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); | 242 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); |
235 | - generateService(srcPath, apiModel); | 243 | + generateRepository(srcPath, apiModel, isCover); |
236 | } | 244 | } |
237 | System.out.println("处理完成"); | 245 | System.out.println("处理完成"); |
238 | } | 246 | } |
239 | 247 | ||
240 | - public static void generateVo(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName) throws Exception{ | 248 | + public static void generateService(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName, boolean isCover) throws Exception{ |
241 | //取数据库连接 | 249 | //取数据库连接 |
242 | Connection conn = getConnection(host, port, user, password, dbName); | 250 | Connection conn = getConnection(host, port, user, password, dbName); |
243 | //初始化要生成的表列表 | 251 | //初始化要生成的表列表 |
@@ -259,7 +267,34 @@ public class GenerateCode { | @@ -259,7 +267,34 @@ public class GenerateCode { | ||
259 | } | 267 | } |
260 | 268 | ||
261 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); | 269 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); |
262 | - generateVo(srcPath, apiModel); | 270 | + generateService(srcPath, apiModel, isCover); |
271 | + } | ||
272 | + System.out.println("处理完成"); | ||
273 | + } | ||
274 | + | ||
275 | + public static void generateVo(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName, boolean isCover) throws Exception{ | ||
276 | + //取数据库连接 | ||
277 | + Connection conn = getConnection(host, port, user, password, dbName); | ||
278 | + //初始化要生成的表列表 | ||
279 | + List<String> tableNameList = getListTableName(tableNameStr, dbName, conn); | ||
280 | + for (int i = 0; i < tableNameList.size(); i++) { | ||
281 | + | ||
282 | + String tableNameCurr = (String) tableNameList.get(i); | ||
283 | + | ||
284 | + //取得表中所有列 | ||
285 | + Vector<MysqlTableColumn> columnsInTable = MysqlTableColumn.GetTableInfo(conn, dbName, tableNameCurr, "%", "mysql"); | ||
286 | + if (columnsInTable == null || columnsInTable.size() == 0) { | ||
287 | + System.out.println(tableNameCurr + " : 生成失败,得不到表中列明"); | ||
288 | + continue; | ||
289 | + } | ||
290 | + MysqlTableColumn pkcolum = MysqlTableColumn.getPKColum(columnsInTable); | ||
291 | + if (pkcolum == null) { | ||
292 | + System.out.println(tableNameCurr + " : 生成失败,未设置主键"); | ||
293 | + continue; | ||
294 | + } | ||
295 | + | ||
296 | + ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); | ||
297 | + generateVo(srcPath, apiModel, isCover); | ||
263 | } | 298 | } |
264 | System.out.println("处理完成"); | 299 | System.out.println("处理完成"); |
265 | } | 300 | } |
@@ -300,48 +335,48 @@ public class GenerateCode { | @@ -300,48 +335,48 @@ public class GenerateCode { | ||
300 | return out.toString(); | 335 | return out.toString(); |
301 | } | 336 | } |
302 | 337 | ||
303 | - private static void generateDto(String srcPath, ApiModel apiModel) throws Exception{ | 338 | + private static void generateDto(String srcPath, ApiModel apiModel, boolean isCover) throws Exception{ |
304 | String modelPath = apiModel.getBasePackage().replace(".", File.separator); | 339 | String modelPath = apiModel.getBasePackage().replace(".", File.separator); |
305 | String filePath = srcPath+File.separator+modelPath+File.separator+"bean"+File.separator+"dto"; | 340 | String filePath = srcPath+File.separator+modelPath+File.separator+"bean"+File.separator+"dto"; |
306 | - Tools.createFile(filePath, apiModel.getDtoClassSimpleName()+".java", renderByTemplate("DtoTemplate.ftl", apiModel), false); | 341 | + Tools.createFile(filePath, apiModel.getDtoClassSimpleName()+".java", renderByTemplate("DtoTemplate.ftl", apiModel), isCover); |
307 | } | 342 | } |
308 | 343 | ||
309 | - private static void generateEntity(String srcPath, ApiModel apiModel) throws Exception{ | 344 | + private static void generateEntity(String srcPath, ApiModel apiModel, boolean isCover) throws Exception{ |
310 | String modelPath = apiModel.getBasePackage().replace(".", File.separator); | 345 | String modelPath = apiModel.getBasePackage().replace(".", File.separator); |
311 | String filePath = srcPath+File.separator+modelPath+File.separator+"bean"+File.separator+"entity"; | 346 | String filePath = srcPath+File.separator+modelPath+File.separator+"bean"+File.separator+"entity"; |
312 | - Tools.createFile(filePath, apiModel.getEntityClassSimpleName()+".java", renderByTemplate("EntityTemplate.ftl", apiModel), false); | 347 | + Tools.createFile(filePath, apiModel.getEntityClassSimpleName()+".java", renderByTemplate("EntityTemplate.ftl", apiModel), isCover); |
313 | } | 348 | } |
314 | 349 | ||
315 | - private static void generateManageController(String srcPath, ApiModel apiModel) throws Exception{ | 350 | + private static void generateManageController(String srcPath, ApiModel apiModel, boolean isCover) throws Exception{ |
316 | String modelPath = apiModel.getBasePackage().replace(".", File.separator); | 351 | String modelPath = apiModel.getBasePackage().replace(".", File.separator); |
317 | String filePath = srcPath+File.separator+modelPath+File.separator+"controller"+File.separator+"manage"; | 352 | String filePath = srcPath+File.separator+modelPath+File.separator+"controller"+File.separator+"manage"; |
318 | - Tools.createFile(filePath, apiModel.getControllerClassName()+".java", renderByTemplate("ManageControllerTemplate.ftl", apiModel), false); | 353 | + Tools.createFile(filePath, apiModel.getControllerClassName()+".java", renderByTemplate("ManageControllerTemplate.ftl", apiModel), isCover); |
319 | } | 354 | } |
320 | 355 | ||
321 | - private static void generateV1Controller(String srcPath, ApiModel apiModel) throws Exception{ | 356 | + private static void generateV1Controller(String srcPath, ApiModel apiModel, boolean isCover) throws Exception{ |
322 | String modelPath = apiModel.getBasePackage().replace(".", File.separator); | 357 | String modelPath = apiModel.getBasePackage().replace(".", File.separator); |
323 | String filePath = srcPath+File.separator+modelPath+File.separator+"controller"+File.separator+"v1"; | 358 | String filePath = srcPath+File.separator+modelPath+File.separator+"controller"+File.separator+"v1"; |
324 | - Tools.createFile(filePath, apiModel.getControllerClassName()+".java", renderByTemplate("V1ControllerTemplate.ftl", apiModel), false); | 359 | + Tools.createFile(filePath, apiModel.getControllerClassName()+".java", renderByTemplate("V1ControllerTemplate.ftl", apiModel), isCover); |
325 | } | 360 | } |
326 | 361 | ||
327 | - private static void generateRepository(String srcPath, ApiModel apiModel) throws Exception{ | 362 | + private static void generateRepository(String srcPath, ApiModel apiModel, boolean isCover) throws Exception{ |
328 | String modelPath = apiModel.getBasePackage().replace(".", File.separator); | 363 | String modelPath = apiModel.getBasePackage().replace(".", File.separator); |
329 | String filePath = srcPath+File.separator+modelPath+File.separator+"repository"; | 364 | String filePath = srcPath+File.separator+modelPath+File.separator+"repository"; |
330 | - Tools.createFile(filePath, apiModel.getRepositoryClassSimpleName()+".java", renderByTemplate("RepositoryTemplate.ftl", apiModel), false); | 365 | + Tools.createFile(filePath, apiModel.getRepositoryClassSimpleName()+".java", renderByTemplate("RepositoryTemplate.ftl", apiModel), isCover); |
331 | } | 366 | } |
332 | 367 | ||
333 | - private static void generateService(String srcPath, ApiModel apiModel) throws Exception{ | 368 | + private static void generateService(String srcPath, ApiModel apiModel, boolean isCover) throws Exception{ |
334 | String modelPath = apiModel.getBasePackage().replace(".", File.separator); | 369 | String modelPath = apiModel.getBasePackage().replace(".", File.separator); |
335 | String filePath = srcPath+File.separator+modelPath+File.separator+"service"; | 370 | String filePath = srcPath+File.separator+modelPath+File.separator+"service"; |
336 | - Tools.createFile(filePath, apiModel.getServiceClassSimpleName()+".java", renderByTemplate("ServiceTemplate.ftl", apiModel), false); | 371 | + Tools.createFile(filePath, apiModel.getServiceClassSimpleName()+".java", renderByTemplate("ServiceTemplate.ftl", apiModel), isCover); |
337 | 372 | ||
338 | String fileImplPath = srcPath+File.separator+modelPath+File.separator+"service"+File.separator+"impl"; | 373 | String fileImplPath = srcPath+File.separator+modelPath+File.separator+"service"+File.separator+"impl"; |
339 | - Tools.createFile(fileImplPath, apiModel.getServiceImplClassSimpleName()+".java", renderByTemplate("ServiceImplTemplate.ftl", apiModel), false); | 374 | + Tools.createFile(fileImplPath, apiModel.getServiceImplClassSimpleName()+".java", renderByTemplate("ServiceImplTemplate.ftl", apiModel), isCover); |
340 | } | 375 | } |
341 | 376 | ||
342 | - private static void generateVo(String srcPath, ApiModel apiModel) throws Exception{ | 377 | + private static void generateVo(String srcPath, ApiModel apiModel, boolean isCover) throws Exception{ |
343 | String modelPath = apiModel.getBasePackage().replace(".", File.separator); | 378 | String modelPath = apiModel.getBasePackage().replace(".", File.separator); |
344 | String filePath = srcPath+File.separator+modelPath+File.separator+"bean"+File.separator+"vo"; | 379 | String filePath = srcPath+File.separator+modelPath+File.separator+"bean"+File.separator+"vo"; |
345 | - Tools.createFile(filePath, apiModel.getVoClassSimpleName()+".java", renderByTemplate("VoTemplate.ftl", apiModel), false); | 380 | + Tools.createFile(filePath, apiModel.getVoClassSimpleName()+".java", renderByTemplate("VoTemplate.ftl", apiModel), isCover); |
346 | } | 381 | } |
347 | } | 382 | } |