GenerateVCSDP.java
4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package com.taover.business;
import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Vector;
import com.taover.base.template.model.bussiness.EnvironmentModel;
import com.taover.db.GenerateDao;
import com.taover.db.GeneratePO;
import com.taover.db.TableColumn;
import com.taover.db.Tools;
import com.taover.tools.StringUtil;
public class GenerateVCSDP {
public static void main(String[] args) {
try {
generate();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void generate() throws Exception{
//读取配置文件
Properties properties = Tools.getProperties();
//取数据库连接
Connection conn = Tools.getConnection(properties);
//初始化要生成的表列表
List<String> tableNameList = new ArrayList<String>();
//读取基本信息
String outputPath = properties.getProperty("OutputPath");
String schameName = properties.getProperty("SchameName");
String dbLikeStr = properties.getProperty("DBLikeStr");
String dbType = properties.getProperty("dbtype");
String dbPackagePath = properties.getProperty("packageName");
String tableName = properties.getProperty("TableName");
//读取配置文件信息-Controller、Service层需要
String modulePackageInfo = properties.getProperty("modulePackageInfo");
String moduleFilePath = properties.getProperty("moduleFilePath");
String dbPackageInfo = properties.getProperty("dbPackageInfo");
//如果文件已存在是否覆盖
boolean coverWhenFileExists = false;
if(properties.getProperty("coverWhenFileExists") != null){
coverWhenFileExists = Boolean.valueOf(properties.getProperty("coverWhenFileExists"));
}
//读取配置文件信息-HTML、JS需要
String webRootPath = properties.getProperty("WebRootPath");
if("mysql".equalsIgnoreCase(dbType)){
schameName = schameName.toUpperCase();
}
if (!dbPackagePath.substring(dbPackagePath.length()-1).equals("."))
dbPackagePath += ".";
if ("ALL".equalsIgnoreCase(tableName) ) {
String sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '"+schameName+"'";
ResultSet rs = Tools.executeQuery(Tools.createStmt(conn), sql);
if (null == rs)
return ;
try {
while (rs.next()) {
tableNameList.add(rs.getString("Table_name"));
}
} catch (SQLException e) {
e.printStackTrace();
}
Tools.close(rs);
} else {
if("mysql".equalsIgnoreCase(dbType)){
// tableName = tableName.toUpperCase();
}
String[] TableNameArr = tableName.split(",");
for (int i = 0; i < TableNameArr.length; i++)
tableNameList.add(TableNameArr[i]);
}
for (int i = 0; i < tableNameList.size(); i++) {
String tableNameCurr = (String) tableNameList.get(i);
// 取得表中所有列
Vector<TableColumn> columnsInTable = TableColumn.GetTableInfo(conn, schameName, tableNameCurr, dbLikeStr, dbType);
if (columnsInTable == null || columnsInTable.size() == 0) {
System.out.println(tableNameCurr + " : 生成失败,得不到表中列明");
continue;
}
TableColumn pkcolum = TableColumn.getPKColum(columnsInTable);
if (pkcolum == null) {
System.out.println(tableNameCurr + " : 生成失败,未设置主键");
continue;
}
// 生成po类
GeneratePO.generatePO(outputPath, dbPackagePath, columnsInTable);
// 生成Dao
GenerateDao.table2dao(outputPath, dbPackagePath, columnsInTable, dbType);
String beanClassName = StringUtil.formatBeanNameFirstUpper(tableNameCurr);
String poPackageInfo = dbPackageInfo + "." + beanClassName.toLowerCase();
String moduleName = tableNameCurr.split("_")[0];
EnvironmentModel envir = EnvironmentModel.createEnvironmentModel(modulePackageInfo, moduleFilePath, poPackageInfo, beanClassName, moduleName);
//生成Controller层
GenerateController.generateController(envir, coverWhenFileExists, columnsInTable);
//生成Service层
GenerateService.generateService(envir, coverWhenFileExists);
//生成view
GenerateView.generateView(webRootPath, tableNameCurr, columnsInTable, coverWhenFileExists);
System.out.println(tableNameCurr + " : 生成结束");
}
conn.close();
System.out.println("全部结束");
}
}