modify file

This commit is contained in:
luming 2021-04-19 18:13:36 +08:00
parent 0a86d79f8d
commit 66995ca148

View File

@ -218,8 +218,8 @@ public class GeneratorUtil {
* @param secondaryPackageName 二级包名称实体所在的包位置除去主包名后的位置 * @param secondaryPackageName 二级包名称实体所在的包位置除去主包名后的位置
* @param type 类型 po entity dto mapper service repository controller * @param type 类型 po entity dto mapper service repository controller
*/ */
public static void generatorByTemplate(List<Column> list,String tableName, String packageName, String secondaryPackageName, String type) { public static void generatorByTemplate(List<Column> list, String tableName, String packageName, String secondaryPackageName, String type) {
String templatePath = String.format("src/main/resources/template/%s.ftl",toLowerCase(type)); String templatePath = String.format("src/main/resources/template/%s.ftl", toLowerCase(type));
String moduleName; String moduleName;
//如果有前缀去除 //如果有前缀去除
String className = tableName; String className = tableName;
@ -248,6 +248,7 @@ public class GeneratorUtil {
} }
String dir = String.format("%s-%s/%s/%s/", CONFIG.getProjectName(), moduleName, package2Path(CONFIG.getPackageName()), package2Path(secondaryPackageName)); String dir = String.format("%s-%s/%s/%s/", CONFIG.getProjectName(), moduleName, package2Path(CONFIG.getPackageName()), package2Path(secondaryPackageName));
String filePath = dir + className + SUFFIX; String filePath = dir + className + SUFFIX;
File file = new File(filePath);
try { try {
// 文件夹不存在创建 // 文件夹不存在创建
if (!new File(dir).exists()) { if (!new File(dir).exists()) {
@ -255,7 +256,7 @@ public class GeneratorUtil {
// System.out.println("PO 文件夹创建成功"); // System.out.println("PO 文件夹创建成功");
} }
//创建文件 //创建文件
if (!new File(filePath).exists()) { if (!file.exists()) {
new File(filePath).createNewFile(); new File(filePath).createNewFile();
System.out.println("=== " + type + ":[" + className + " ] 创建成功 ==="); System.out.println("=== " + type + ":[" + className + " ] 创建成功 ===");
} }
@ -263,7 +264,12 @@ public class GeneratorUtil {
} }
Configuration configuration = new Configuration(Configuration.VERSION_2_3_0); Configuration configuration = new Configuration(Configuration.VERSION_2_3_0);
Template template = configuration.getTemplate(templatePath); Template template = configuration.getTemplate(templatePath);
Map<String, Object> data = new HashMap<>();
data.put("package", packageName + '.' + secondaryPackageName);
data.put("table_name", tableName);
data.put("class_name", className);
data.put("columns", list);
template.process(data, new FileWriter(file));
} catch (TemplateNotFoundException e) { } catch (TemplateNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} catch (ParseException e) { } catch (ParseException e) {
@ -272,6 +278,8 @@ public class GeneratorUtil {
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
} }
} }