|
@@ -54,6 +54,37 @@ public class MybatisPlusGenCode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public static String getTableInfo(String tableName) {
|
|
|
+ String tableInfo = "";
|
|
|
+ try {
|
|
|
+ //1、注册JDBC驱动
|
|
|
+ Class.forName(DRIVER_CLASS);
|
|
|
+ //2、获取数据库连接
|
|
|
+ Connection connection = DriverManager.getConnection(CONNECTION_URL, USER_ID, PASS_WORD);
|
|
|
+ //3、操作数据库
|
|
|
+ Statement statement = connection.createStatement();//获取操作数据库的对象
|
|
|
+
|
|
|
+ //String sql = "SELECT COLUMN_NAME,IS_NULLABLE,COLUMN_COMMENT,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,COLUMN_KEY " +
|
|
|
+
|
|
|
+ String sql = "SELECT table_name,table_comment FROM information_schema.TABLES WHERE table_schema = '" + DATABASE_NAME + "' AND table_name = '" + tableName + "'";
|
|
|
+ ResultSet resultSet = statement.executeQuery(sql);//执行sql,获取结果集
|
|
|
+ System.out.println("sql:" + sql);
|
|
|
+ while (resultSet.next()) {
|
|
|
+ //遍历结果集,取出数据
|
|
|
+ //输出数据
|
|
|
+ tableInfo = resultSet.getString("table_comment");
|
|
|
+ }
|
|
|
+ //4、关闭结果集、数据库操作对象、数据库连接
|
|
|
+ resultSet.close();
|
|
|
+ statement.close();
|
|
|
+ connection.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new RuntimeException("数据库连接错误!");
|
|
|
+ }
|
|
|
+ return tableInfo;
|
|
|
+ }
|
|
|
+
|
|
|
public static List<ColumnVo> getIdType(String tableName) {
|
|
|
|
|
|
List<ColumnVo> columnVos = new ArrayList<>();
|
|
@@ -113,6 +144,8 @@ public class MybatisPlusGenCode {
|
|
|
ve.init();
|
|
|
VelocityContext ctx = new VelocityContext();
|
|
|
ctx.put("tableName", tableName);
|
|
|
+ String tableInfo = getTableInfo(tableName);
|
|
|
+ ctx.put("tableInfo", tableInfo);
|
|
|
//获取列数据
|
|
|
List<ColumnVo> mysqlDataType = getIdType(tableName);
|
|
|
for (ColumnVo columnVo : mysqlDataType) {
|