ApiModel.java
6.32 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package com.taover.codegenerate.bazhuayun.model;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import com.taover.codegenerate.db.TableColumn;
import com.taover.codegenerate.model.po.ColumnModel;
import com.taover.codegenerate.model.po.TableModel;
import com.taover.codegenerate.tools.StringUtil;
public class ApiModel {
private String basePackage;
private String version;
private String dtoClassSimpleName;
private String entityClassSimpleName;
private String serviceClassSimpleName;
private String serviceClassFieldName;
private String serviceImplClassSimpleName;
private String repositoryClassSimpleName;
private String repositoryClassFieldName;
private String voClassSimpleName;
private String controllerMap;
private String controllerClassName;
private String toStringMethodBody;
private TableModel tablemodel;
public ApiModel(String dbName, String tableName, Vector<TableColumn> columnsInTable, String version, String basePackage) throws SQLException{
this.tablemodel = createTableModel(dbName, columnsInTable);
this.version = version;
this.basePackage = basePackage;
String classSimpleNamePreffix = StringUtil.formatBeanNameFirstUpper(tableName);
String classFieldNamePreffix = StringUtil.formatBeanNameFirstLow(tableName);
this.dtoClassSimpleName = classSimpleNamePreffix+"Dto";
this.entityClassSimpleName = classSimpleNamePreffix+"Entity";
this.repositoryClassFieldName = classFieldNamePreffix+"Repository";
this.repositoryClassSimpleName = classSimpleNamePreffix+"Repository";
this.serviceClassFieldName = classFieldNamePreffix+"Service";
this.serviceClassSimpleName = classSimpleNamePreffix+"Service";
this.serviceImplClassSimpleName = classSimpleNamePreffix+"ServiceImpl";
this.voClassSimpleName = classSimpleNamePreffix+"Vo";
this.toStringMethodBody = getEntityToString(columnsInTable);
this.controllerClassName = classSimpleNamePreffix+"Controller";
this.controllerMap = tableName.replace("_", "");
}
private String getEntityToString(Vector<TableColumn> ColumnsInTable) throws SQLException {
StringBuffer returnbuffer = new StringBuffer();
returnbuffer.append("[");
int iLen = ColumnsInTable.size() - 1;
for (int i = 0; i <= iLen; i++) {
TableColumn colum = ColumnsInTable.get(i);
String tempName = colum.getColumBeanLName();
if (i == iLen) {
if (i == 0) {
returnbuffer.append(tempName).append("=").append("\"").append("+").append(tempName);
}else{
returnbuffer.append("\",").append(tempName).append("=").append("\"").append("+").append(tempName);
}
} else {
if (i == 0) {
returnbuffer.append(tempName).append("=").append("\"").append("+").append(tempName).append("+");
}else{
returnbuffer.append("\",").append(tempName).append("=").append("\"").append("+").append(tempName).append("+");
}
}
}
returnbuffer.append("+\"]\"");
return returnbuffer.toString();
}
private TableModel createTableModel(String dbName, Vector<TableColumn> columnsInTable){
TableModel tm = new TableModel();
List<ColumnModel> clist = new ArrayList<ColumnModel>();
int len = columnsInTable.size();
for (int i = 0; i < len; i++) {
TableColumn colum = columnsInTable.get(i);
ColumnModel cm = new ColumnModel();
String sColumnBeanName = colum.getColumBeanLName();
String sSetColumnBeanName = colum.getColumBeanUName();
cm.setColumnName(sColumnBeanName);
cm.setColumnUName(colum.getColumnName());
cm.setColumnMethodName(sSetColumnBeanName);
cm.setColumnRemarks(colum.getRemarks());
cm.setColumnJAVAType(colum.getJAVADataType());
cm.setPrimaryKey(colum.isPrimaryKey());
clist.add(cm);
}
tm.setColumnlist(clist);
tm.setTableName(columnsInTable.get(0).getTableName());
tm.setSchemeName(dbName);
return tm;
}
public String getBasePackage() {
return basePackage;
}
public void setBasePackage(String basePackage) {
this.basePackage = basePackage;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getDtoClassSimpleName() {
return dtoClassSimpleName;
}
public void setDtoClassSimpleName(String dtoClassSimpleName) {
this.dtoClassSimpleName = dtoClassSimpleName;
}
public String getEntityClassSimpleName() {
return entityClassSimpleName;
}
public void setEntityClassSimpleName(String entityClassSimpleName) {
this.entityClassSimpleName = entityClassSimpleName;
}
public String getServiceClassSimpleName() {
return serviceClassSimpleName;
}
public void setServiceClassSimpleName(String serviceClassSimpleName) {
this.serviceClassSimpleName = serviceClassSimpleName;
}
public String getServiceClassFieldName() {
return serviceClassFieldName;
}
public void setServiceClassFieldName(String serviceClassFieldName) {
this.serviceClassFieldName = serviceClassFieldName;
}
public String getServiceImplClassSimpleName() {
return serviceImplClassSimpleName;
}
public void setServiceImplClassSimpleName(String serviceImplClassSimpleName) {
this.serviceImplClassSimpleName = serviceImplClassSimpleName;
}
public String getRepositoryClassSimpleName() {
return repositoryClassSimpleName;
}
public void setRepositoryClassSimpleName(String repositoryClassSimpleName) {
this.repositoryClassSimpleName = repositoryClassSimpleName;
}
public String getRepositoryClassFieldName() {
return repositoryClassFieldName;
}
public void setRepositoryClassFieldName(String repositoryClassFieldName) {
this.repositoryClassFieldName = repositoryClassFieldName;
}
public String getVoClassSimpleName() {
return voClassSimpleName;
}
public void setVoClassSimpleName(String voClassSimpleName) {
this.voClassSimpleName = voClassSimpleName;
}
public String getControllerMap() {
return controllerMap;
}
public void setControllerMap(String controllerMap) {
this.controllerMap = controllerMap;
}
public String getControllerClassName() {
return controllerClassName;
}
public void setControllerClassName(String controllerClassName) {
this.controllerClassName = controllerClassName;
}
public String getToStringMethodBody() {
return toStringMethodBody;
}
public void setToStringMethodBody(String toStringMethodBody) {
this.toStringMethodBody = toStringMethodBody;
}
public TableModel getTablemodel() {
return tablemodel;
}
public void setTablemodel(TableModel tablemodel) {
this.tablemodel = tablemodel;
}
}