【update】添加注释与重命名变量
This commit is contained in:
+9
-9
@@ -8,16 +8,16 @@ public class CodegenDatasourceConfig {
|
||||
/**
|
||||
* 加载配置
|
||||
* @date 2021/4/2 10:29
|
||||
* @param DIVERNAME
|
||||
* @param URL
|
||||
* @param USERNAME
|
||||
* @param PASSWORD
|
||||
* @param driverName 驱动
|
||||
* @param url 地址
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
* @return void
|
||||
*/
|
||||
public static void initDbConfig(String DIVERNAME, String URL, String USERNAME, String PASSWORD) {
|
||||
CodeConfigProperties.driverName = DIVERNAME;
|
||||
CodeConfigProperties.databaseUrl = URL;
|
||||
CodeConfigProperties.username = USERNAME;
|
||||
CodeConfigProperties.password = PASSWORD;
|
||||
public static void initDbConfig(String driverName, String url, String username, String password) {
|
||||
CodeConfigProperties.driverName = driverName;
|
||||
CodeConfigProperties.databaseUrl = url;
|
||||
CodeConfigProperties.username = username;
|
||||
CodeConfigProperties.password = password;
|
||||
}
|
||||
}
|
||||
+14
-2
@@ -456,7 +456,12 @@ public class DbReadTableUtil {
|
||||
foreignKey = foreignKey.substring(0, 1).toUpperCase() + foreignKey.substring(1);
|
||||
return foreignKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置ColumnVo
|
||||
* @date 2021/4/6 13:45
|
||||
* @param columnVo
|
||||
* @return void
|
||||
*/
|
||||
private static void setupColumnVo(ColumnVo columnVo) {
|
||||
String fieldType = columnVo.getFieldType();
|
||||
String scale = columnVo.getScale();
|
||||
@@ -486,7 +491,14 @@ public class DbReadTableUtil {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回字段类型
|
||||
* @date 2021/4/6 13:43
|
||||
* @param value
|
||||
* @param precision
|
||||
* @param scale
|
||||
* @return java.lang.String
|
||||
*/
|
||||
private static String getFieldType(String value, String precision, String scale) {
|
||||
if (value.contains("char")) {
|
||||
value = "java.lang.String";
|
||||
|
||||
+18
-3
@@ -18,7 +18,12 @@ public class CreateFileConfig {
|
||||
log.debug("----stylePath-----------------" + this.stylePath);
|
||||
this.templatePath = templatePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 fileList
|
||||
* @date 2021/4/6 13:47
|
||||
* @param file
|
||||
* @return void
|
||||
*/
|
||||
private void setFileList(File file) {
|
||||
this.convertArrToList(file);
|
||||
}
|
||||
@@ -31,11 +36,21 @@ public class CreateFileConfig {
|
||||
private void convertArrToList(File... files) {
|
||||
this.templateRootDirs = Arrays.asList(files);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取stylePath
|
||||
* @date 2021/4/6 13:47
|
||||
* @param
|
||||
* @return java.lang.String
|
||||
*/
|
||||
public String getStylePath() {
|
||||
return this.stylePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 stylePath
|
||||
* @date 2021/4/6 13:46
|
||||
* @param stylePath
|
||||
* @return void
|
||||
*/
|
||||
public void setStylePath(String stylePath) {
|
||||
this.stylePath = stylePath;
|
||||
}
|
||||
|
||||
+59
-22
@@ -40,18 +40,29 @@ public class BaseCodeGenerate {
|
||||
log.debug("--------generate----projectPath--------" + projectPath);
|
||||
|
||||
for(int i = 0; i < createFileConfig.listTemplateRootDirs().size(); ++i) {
|
||||
// 模板根目录
|
||||
// 获取一个模板根目录
|
||||
File templateRootDir = (File)createFileConfig.listTemplateRootDirs().get(i);
|
||||
this.a(projectPath, templateRootDir, configMap, createFileConfig);
|
||||
this.createOutPutFile(projectPath, templateRootDir, configMap, createFileConfig);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void a(String projectPath, File templateRootDir, Map<String, Object> configMap, CreateFileConfig createFileConfig) throws Exception {
|
||||
/**
|
||||
* 生成输出目录的文件
|
||||
* @author 马志朝
|
||||
* @date 2021/4/6 14:25
|
||||
* @param projectPath 项目路径
|
||||
* @param templateRootDir 模板根目录
|
||||
* @param configMap 表配置
|
||||
* @param createFileConfig 生成文件配置
|
||||
* @return void
|
||||
*/
|
||||
protected void createOutPutFile(String projectPath, File templateRootDir, Map<String, Object> configMap, CreateFileConfig createFileConfig) throws Exception {
|
||||
// 模板目录为空
|
||||
if (templateRootDir == null) {
|
||||
throw new IllegalStateException("'templateRootDir' must be not null");
|
||||
} else {
|
||||
log.info(" load template from templateRootDir = '" + templateRootDir.getAbsolutePath() + "',stylePath ='" + createFileConfig.getStylePath() + "', out GenerateRootDir:" + com.jero.codegenerate.properties.CodeConfigProperties.projectPath);
|
||||
// 获取模板目录下的模板
|
||||
List templateFileList = FileHelper.listFileAndSort(templateRootDir);
|
||||
log.debug("----srcFiles----size-----------" + templateFileList.size());
|
||||
log.debug("----srcFiles----list------------" + templateFileList.toString());
|
||||
@@ -59,13 +70,22 @@ public class BaseCodeGenerate {
|
||||
for(int i = 0; i < templateFileList.size(); ++i) {
|
||||
// 获取一个模板文件
|
||||
File srcFile = (File)templateFileList.get(i);
|
||||
this.a(projectPath, templateRootDir, configMap, srcFile, createFileConfig);
|
||||
this.createOutPutFile(projectPath, templateRootDir, configMap, srcFile, createFileConfig);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void a(String projectPath, File templateRootDir, Map<String, Object> configMap, File srcFile, CreateFileConfig createFileConfig) throws Exception {
|
||||
/**
|
||||
* 生成输出目录的文件
|
||||
* @date 2021/4/6 14:33
|
||||
* @param projectPath 项目路径
|
||||
* @param templateRootDir 模板根目录
|
||||
* @param configMap 表配置
|
||||
* @param srcFile 一个模板文件
|
||||
* @param createFileConfig 生成文件配置
|
||||
* @return void
|
||||
*/
|
||||
protected void createOutPutFile(String projectPath, File templateRootDir, Map<String, Object> configMap, File srcFile, CreateFileConfig createFileConfig) throws Exception {
|
||||
log.debug("-------templateRootDir--" + templateRootDir.getPath());
|
||||
log.debug("-------srcFile--" + srcFile.getPath());
|
||||
String templateFilePath = FileHelper.getDirExcludeRootDir(templateRootDir, srcFile);
|
||||
@@ -79,27 +99,40 @@ public class BaseCodeGenerate {
|
||||
String outputFilepath = getTemplatePath(configMap, templateFilePath, createFileConfig);
|
||||
log.debug("-------outputFilepath--" + outputFilepath);
|
||||
String packageDir;
|
||||
// 输出文件路径以 java 开头
|
||||
if (outputFilepath.startsWith("java")) {
|
||||
// 生成目录位置
|
||||
packageDir = projectPath + File.separator + com.jero.codegenerate.properties.CodeConfigProperties.sourceRootPackage.replace(".", File.separator);
|
||||
outputFilepath = outputFilepath.substring("java".length());
|
||||
outputFilepath = packageDir + outputFilepath;
|
||||
log.debug("-------java----outputFilepath--" + outputFilepath);
|
||||
this.a(templateFilePath, outputFilepath, configMap, createFileConfig);
|
||||
// 生成文件
|
||||
this.createOutPutFile(templateFilePath, outputFilepath, configMap, createFileConfig);
|
||||
// 输出文件路径以 webapp 开头
|
||||
} else if (outputFilepath.startsWith("webapp")) {
|
||||
// 生成目录位置
|
||||
packageDir = projectPath + File.separator + com.jero.codegenerate.properties.CodeConfigProperties.webrootPackage.replace(".", File.separator);
|
||||
outputFilepath = outputFilepath.substring("webapp".length());
|
||||
outputFilepath = packageDir + outputFilepath;
|
||||
log.debug("-------webapp---outputFilepath---" + outputFilepath);
|
||||
this.a(templateFilePath, outputFilepath, configMap, createFileConfig);
|
||||
// 生成文件
|
||||
this.createOutPutFile(templateFilePath, outputFilepath, configMap, createFileConfig);
|
||||
}
|
||||
} catch (Exception var10) {
|
||||
log.error(var10.toString(), var10);
|
||||
} catch (Exception exception) {
|
||||
log.error(exception.toString(), exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void a(String templateFilePath, String outputFilepath, Map<String, Object> configMap, CreateFileConfig createFileConfig) throws Exception {
|
||||
/**
|
||||
* 生成输出目录的文件
|
||||
* @date 2021/4/6 14:14
|
||||
* @param templateFilePath 模板相对路径
|
||||
* @param outputFilepath 输出文件路径
|
||||
* @param configMap 表配置
|
||||
* @param createFileConfig 生成文件配置
|
||||
* @return void
|
||||
*/
|
||||
protected void createOutPutFile(String templateFilePath, String outputFilepath, Map<String, Object> configMap, CreateFileConfig createFileConfig) throws Exception {
|
||||
if (outputFilepath.endsWith("i")) {
|
||||
//将末尾的'i'去除
|
||||
outputFilepath = outputFilepath.substring(0, outputFilepath.length() - 1);
|
||||
@@ -110,11 +143,13 @@ public class BaseCodeGenerate {
|
||||
// 生成文件
|
||||
File file = FileHelper.createFile(outputFilepath);
|
||||
log.info("[generate]\t template:" + templateFilePath + " ==> " + outputFilepath);
|
||||
//根据template写入数据
|
||||
FreemarkerHelper.fillDataIntoFileByTemplate(template, configMap, file, characterSet);
|
||||
// 文件名开头是否非法
|
||||
if (!this.isStartWithIllegalStr(file)) {
|
||||
this.messageList.add("生成成功:" + outputFilepath);
|
||||
}
|
||||
|
||||
// 是否以非法字符串开头
|
||||
if (this.isStartWithIllegalStr(file)) {
|
||||
this.a(file, "#segment#");
|
||||
}
|
||||
@@ -131,7 +166,7 @@ public class BaseCodeGenerate {
|
||||
return FreemarkerHelper.getConfiguration(createFileConfig.listTemplateRootDirs(), characterSet, templateFilePath).getTemplate(templateFilePath);
|
||||
}
|
||||
/**
|
||||
* 是否以指定非法字符开头
|
||||
* 是否文件名以指定非法字符开头
|
||||
* @date 2021/4/2 17:18
|
||||
* @param file 文件
|
||||
* @return boolean
|
||||
@@ -159,9 +194,11 @@ public class BaseCodeGenerate {
|
||||
while(true) {
|
||||
String s;
|
||||
while((s = bf.readLine()) != null) {
|
||||
// 若以指定str开头
|
||||
// 若以指定str开头,长度大于0
|
||||
if (s.trim().length() > 0 && s.startsWith(str)) {
|
||||
// 截取指定str后
|
||||
String substring = s.substring(str.length());
|
||||
// 父目录
|
||||
String parentPath = file.getParentFile().getAbsolutePath();
|
||||
substring = parentPath + File.separator + substring;
|
||||
log.info("[generate]\t split file:" + file.getAbsolutePath() + " ==> " + substring);
|
||||
@@ -174,8 +211,8 @@ public class BaseCodeGenerate {
|
||||
}
|
||||
}
|
||||
|
||||
for(int var29 = 0; var29 < list.size(); ++var29) {
|
||||
((Writer)list.get(var29)).close();
|
||||
for(int j = 0; j < list.size(); ++j) {
|
||||
((Writer)list.get(j)).close();
|
||||
}
|
||||
|
||||
bf.close();
|
||||
@@ -185,12 +222,12 @@ public class BaseCodeGenerate {
|
||||
flag = false;
|
||||
break label341;
|
||||
}
|
||||
} catch (FileNotFoundException var25) {
|
||||
var25.printStackTrace();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
flag = false;
|
||||
break label342;
|
||||
} catch (IOException var26) {
|
||||
var26.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
flag = false;
|
||||
} finally {
|
||||
if (flag) {
|
||||
|
||||
Reference in New Issue
Block a user