main
黄海 10 months ago
parent 00ecd78aef
commit e0b60c697b

@ -1,8 +1,10 @@
package com.dsideal.Tools; package com.dsideal.Tools;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONObject;
import com.dsideal.Utils.dsKit; import com.dsideal.Utils.dsKit;
import com.jfinal.kit.PropKit; import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin; import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.hikaricp.HikariCpPlugin; import com.jfinal.plugin.hikaricp.HikariCpPlugin;
@ -50,9 +52,13 @@ public class GenerateCode {
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static void getStructure(Connection conn, String table) throws Exception { public static JSONObject getStructure(Connection conn, String table) throws Exception {
StringBuilder sb = new StringBuilder(); //表结构的描述JSON对象
JSONObject jo = new JSONObject();
//字段,不包含主键
Map<String, String> map = new LinkedHashMap<>();
StringBuilder sb = new StringBuilder();
//表注释 //表注释
String comment = ""; String comment = "";
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
@ -93,7 +99,13 @@ public class GenerateCode {
} }
Type = Type.toUpperCase(); Type = Type.toUpperCase();
// System.out.println(rs.getString("Key"));//是不是主键 PRI是主键 //记录主键
if (rs.getString("Key").equals("PRI")) {
jo.put("key", Field);
} else {//否则记录到map中
map.put(Field, dataTypeMap.get(Type));
}
sb.append(" // " + rs.getString("Comment") + "\n"); sb.append(" // " + rs.getString("Comment") + "\n");
sb.append(" @Getter\n"); sb.append(" @Getter\n");
sb.append(" @Setter\n"); sb.append(" @Setter\n");
@ -118,6 +130,8 @@ public class GenerateCode {
//关闭连接 //关闭连接
rs.close(); rs.close();
stmt.close(); stmt.close();
jo.put("fields", map);
return jo;
} }
/** /**
@ -178,8 +192,14 @@ public class GenerateCode {
String tableNames = ""; String tableNames = "";
//表描述 //表描述
for (String table : tables) { for (String table : tables) {
getStructure(conn, table); JSONObject jo = getStructure(conn, table);
tableNames += table + ","; tableNames += table + ",";
if (StrKit.isBlank(jo.getStr("key"))) {
dsKit.print("表" + table + "没有主键,请检查!");
}
//生成代码
autoCode(jo);
} }
//去掉最后的逗号 //去掉最后的逗号
tableNames = tableNames.substring(0, tableNames.length() - 1); tableNames = tableNames.substring(0, tableNames.length() - 1);
@ -191,4 +211,12 @@ public class GenerateCode {
System.out.println(dsKit.getCurrentTimeStr() + " 恭喜,表" + tableNames + "代码已成功生成!"); System.out.println(dsKit.getCurrentTimeStr() + " 恭喜,表" + tableNames + "代码已成功生成!");
} }
/**
*
* @param jo
*/
public void autoCode(JSONObject jo){
}
} }

@ -0,0 +1,10 @@
1、增加
(1) Controller
(2) Model
2、删除
3、修改
4、单条查询
5、列表查询带分页

@ -11,6 +11,14 @@ public class dsKit {
return DateUtil.formatDateTime(DateUtil.date()); return DateUtil.formatDateTime(DateUtil.date());
} }
/**
*
* @param msg
*/
public static void print(String msg){
System.out.println(getCurrentTimeStr()+" "+msg);
}
/** /**
* *
* *

@ -1,4 +1,4 @@
package com.dsideal.base.Model; package com.dsideal.base.Bean;
import lombok.Setter; import lombok.Setter;
import lombok.Getter; import lombok.Getter;

@ -8,7 +8,7 @@ jdbcUrl=jdbc:mysql://10.10.14.210:22066/yltcharge?useUnicode=true&characterEncod
beanPath=D:/dsWork/dsProject/dsUtils/src/main/java beanPath=D:/dsWork/dsProject/dsUtils/src/main/java
# ??bean??? # ??bean???
beanPackage=com.dsideal.base.Model beanPackage=com.dsideal.base.Bean
# ??????? # ???????
tableName=t_sys_loginperson tableName=t_sys_loginperson

@ -8,7 +8,7 @@ jdbcUrl=jdbc:mysql://10.10.14.210:22066/yltcharge?useUnicode=true&characterEncod
beanPath=D:/dsWork/dsProject/dsUtils/src/main/java beanPath=D:/dsWork/dsProject/dsUtils/src/main/java
# ??bean??? # ??bean???
beanPackage=com.dsideal.base.Model beanPackage=com.dsideal.base.Bean
# ??????? # ???????
tableName=t_sys_loginperson tableName=t_sys_loginperson

Loading…
Cancel
Save