|
|
|
@ -131,6 +131,7 @@ public class GenerateCode {
|
|
|
|
|
rs.close();
|
|
|
|
|
stmt.close();
|
|
|
|
|
jo.put("fields", map);
|
|
|
|
|
jo.put("beanName", className);
|
|
|
|
|
return jo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -201,6 +202,10 @@ public class GenerateCode {
|
|
|
|
|
//生成代码
|
|
|
|
|
autoCode(jo);
|
|
|
|
|
}
|
|
|
|
|
if (StrKit.isBlank(tableNames)) {
|
|
|
|
|
dsKit.print("没有找到表,请检查!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//去掉最后的逗号
|
|
|
|
|
tableNames = tableNames.substring(0, tableNames.length() - 1);
|
|
|
|
|
|
|
|
|
@ -214,9 +219,40 @@ public class GenerateCode {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:生成代码
|
|
|
|
|
*
|
|
|
|
|
* @param jo
|
|
|
|
|
*/
|
|
|
|
|
public void autoCode(JSONObject jo){
|
|
|
|
|
|
|
|
|
|
public static void autoCode(JSONObject jo) {
|
|
|
|
|
//不带主键的其它字段,拼接成java的函数声明内容
|
|
|
|
|
// 迭代map将按照插入顺序
|
|
|
|
|
Map<String, String> fields = (Map<String, String>) jo.get("fields");
|
|
|
|
|
String content = "";
|
|
|
|
|
for (Map.Entry<String, String> entry : fields.entrySet()) {
|
|
|
|
|
if (!entry.getKey().equals("create_time") && !entry.getKey().equals("b_use")) {
|
|
|
|
|
content += entry.getValue() + " " + entry.getKey() + ",";//这里必须是反着来的,否则数据类型会重复
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//移除最后一个逗号
|
|
|
|
|
content = content.substring(0, content.length() - 1);
|
|
|
|
|
//后缀名称
|
|
|
|
|
String beanName = jo.getStr("beanName");
|
|
|
|
|
if (beanName.startsWith("T")) {
|
|
|
|
|
beanName = beanName.substring(1);
|
|
|
|
|
}
|
|
|
|
|
//1、增加
|
|
|
|
|
StringBuilder sbAdd = new StringBuilder();
|
|
|
|
|
sbAdd.append(" @Before({POST.class})\n");
|
|
|
|
|
sbAdd.append(" public void add"+beanName+"(" + content + "){\n");
|
|
|
|
|
|
|
|
|
|
sbAdd.append(" }\n");
|
|
|
|
|
|
|
|
|
|
System.out.println(sbAdd);
|
|
|
|
|
//2、删除
|
|
|
|
|
|
|
|
|
|
//3、修改
|
|
|
|
|
|
|
|
|
|
//4、单条查询
|
|
|
|
|
|
|
|
|
|
//5、分页查询
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|