GenerateCS.java
2.69 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
package com.taover.business;
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 com.taover.base.template.model.bussiness.EnvironmentModel;
import com.taover.db.Tools;
import com.taover.tools.StringUtil;
public class GenerateCS {
public static void main(String[] args) throws Exception{
//读取配置文件
Properties properties = Tools.getProperties();
//取数据库连接
Connection conn = Tools.getConnection(properties);
//初始化要生成的表列表
List<String> tableNameList = new ArrayList<String>();
String schameName = properties.getProperty("SchameName");
String createSchame = properties.getProperty("CreateSchame");
String dbType = properties.getProperty("dbtype");
String tableName = properties.getProperty("TableName");
if("mysql".equalsIgnoreCase(dbType)){
//schameName = schameName.toUpperCase();
}
if (createSchame.equalsIgnoreCase("true") || "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]);
}
//读取配置文件信息
String modulePackageInfo = properties.getProperty("modulePackageInfo");
String moduleFilePath = properties.getProperty("moduleFilePath");
String dbPackageInfo = properties.getProperty("dbPackageInfo");
//循环遍历各个表名
for (int i = 0; i < tableNameList.size(); i++) {
String tableNameCurr = (String) tableNameList.get(i);
String beanClassName = StringUtil.formatBeanNameFirstUpper(tableNameCurr);
String poPackageInfo = dbPackageInfo + "." + beanClassName.toLowerCase();
EnvironmentModel envir = EnvironmentModel.createEnvironmentModel(
modulePackageInfo, moduleFilePath, poPackageInfo, beanClassName);
//生成Controller层
GenerateController.generateController(envir, false);
//生成Service层
GenerateService.generateService(envir, false);
System.out.println(tableNameCurr + " : 生成结束");
}
conn.close();
System.out.println("全部结束");
}
}