国网推送
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package com.njcn.harmonic.utils;
|
||||
|
||||
import com.njcn.harmonic.pojo.dto.PqTypicalSourceCreateDTO;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2023/12/7 16:12【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
public class PotoSqlUtil {
|
||||
public static String generateCreateTableSql(Class<?> entityClass) {
|
||||
StringBuilder sql = new StringBuilder("CREATE TABLE ");
|
||||
sql.append(entityClass.getSimpleName()).append(" (");
|
||||
|
||||
Field[] fields = entityClass.getDeclaredFields();
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
Field field = fields[i];
|
||||
if (!Modifier.isStatic(field.getModifiers())) {
|
||||
sql.append(field.getName()).append(" ");
|
||||
Class<?> fieldType = field.getType();
|
||||
if (fieldType == int.class || fieldType == Integer.class) {
|
||||
sql.append("INT");
|
||||
} else if (fieldType == String.class) {
|
||||
sql.append("VARCHAR(255)");
|
||||
} else if (fieldType == double.class || fieldType == Double.class) {
|
||||
sql.append("DOUBLE");
|
||||
} else if (fieldType == float.class || fieldType == Float.class) {
|
||||
sql.append("FLOAT");
|
||||
} else if (fieldType == boolean.class || fieldType == Boolean.class) {
|
||||
sql.append("BOOLEAN");
|
||||
} else if (fieldType == java.util.Date.class) {
|
||||
sql.append("DATE");
|
||||
} else if (fieldType == java.math.BigDecimal.class) {
|
||||
sql.append("decimal");
|
||||
}
|
||||
else {
|
||||
// 其他类型暂不支持,可以根据需要添加
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i < fields.length - 1) {
|
||||
sql.append(", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sql.append(");");
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String createTableSql = generateCreateTableSql(PqTypicalSourceCreateDTO.class);
|
||||
System.out.println(createTableSql);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user