浏览代码

🎨: 整理代码

简化和优化代码生成器相关代码
yangll 3 年之前
父节点
当前提交
7e96098609

+ 1 - 1
tnc-generate/src/main/java/org/jeecg/codegen/config/CodeConfigProperties.java

@@ -42,7 +42,7 @@ public class CodeConfigProperties {
     /** 数据库模式 schema 仅限 postgresql 使用*/
     public static String schemaName;
 
-    /** 项目目录 */
+    /** 生成文件路径,可以是项目路径 */
     public static String projectPath;
 
     /** 模板路径 */

+ 6 - 6
tnc-generate/src/main/java/org/jeecg/codegen/generate/IGenerate.java

@@ -5,12 +5,12 @@ import java.util.Map;
 
 public interface IGenerate {
     /**
-     * 获取配置参
+     * 获取数据模型
      *
-     * @return 配置参
+     * @return 数据模型
      * @throws Exception 异常
      */
-    Map<String, Object> getConfig() throws Exception;
+    Map<String, Object> getDataModel() throws Exception;
 
     /**
      * 生成代码<br>
@@ -41,14 +41,14 @@ public interface IGenerate {
 
     /**
      * 生成代码<br>
-     * 指定项目路径、模板路径和模板风格路径<br><br>
+     * 指定代码生成根路径、模板路径和模板风格路径<br><br>
      *
-     * @param projectPath 项目路径
+     * @param generateRootPath 代码生成根路径,也可以是项目路径
      * @param templatePath 模板路径
      * @param stylePath 模板风格路径
      * @return 生成代码文件路径
      * @throws Exception 异常
      */
-    List<String> generateCodeFile(String projectPath, String templatePath, String stylePath) throws Exception;
+    List<String> generateCodeFile(String generateRootPath, String templatePath, String stylePath) throws Exception;
 
 }

+ 32 - 2
tnc-generate/src/main/java/org/jeecg/codegen/generate/config/CreateFileConfig.java

@@ -21,6 +21,8 @@ public class CreateFileConfig {
 
     /** 模板完整路径 */
     private List<File> templateRootDirs = new ArrayList<>();
+    /** 模板完整路径 */
+    private File templateRootDir;
     /** 模板路径 */
     private String templatePath;
     /** 样式路径 */
@@ -60,8 +62,36 @@ public class CreateFileConfig {
             LOGGER.debug("---JAR--config--classpath-------" + classPath);
         }
 
+        templateRootDir = new File(classPath);
         setTemplateRootDirs(new File(classPath));
-        return this.templateRootDirs;
+        return templateRootDirs;
+    }
+
+    /**
+     * 获取模板路径
+     *
+     * @return 模板路径
+     */
+    public File getTemplateRootDir() {
+        String templateRootPath = getClass().getResource(templatePath).getFile();
+        try {
+            // 转义中文
+            templateRootPath = URLDecoder.decode(templateRootPath, StandardCharsets.UTF_8.name());
+        } catch (UnsupportedEncodingException e) {
+            LOGGER.error(e.getMessage(), e);
+        }
+        // 替换空格
+        String classPath = templateRootPath.replaceAll("%20", " ");
+        classPath = FileHelper.unifyPath(classPath);
+        LOGGER.debug("-------classpath-------" + classPath);
+        // 在jar 包中的路径
+        if (classPath.contains("/BOOT-INF/classes!") || classPath.contains("/BOOT-INF/lib/")) {
+            classPath = System.getProperty("user.dir") + File.separator + "config/jeecg/code-template-online/".replace("/", File.separator);
+            LOGGER.debug("---JAR--config--classpath-------" + classPath);
+        }
+
+        templateRootDir = new File(classPath);
+        return templateRootDir;
     }
 
     /**
@@ -73,7 +103,7 @@ public class CreateFileConfig {
         this.templateRootDirs = Arrays.asList(files);
     }
 
-    private void setTemplateDir(File file) {
+    private void setTemplateRootPath(File file) {
         this.setTemplateRootDirs(file);
     }
 

+ 9 - 10
tnc-generate/src/main/java/org/jeecg/codegen/generate/impl/CodeGenerateOne.java

@@ -10,7 +10,6 @@ import org.jeecg.codegen.generate.impl.base.BaseCodeGenerate;
 import org.jeecg.codegen.generate.pojo.ColumnVo;
 import org.jeecg.codegen.generate.pojo.TableVo;
 import org.jeecg.codegen.generate.util.NonceUtils;
-import org.jeecg.common.constant.enums.CgformEnum;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -61,7 +60,7 @@ public class CodeGenerateOne extends BaseCodeGenerate implements IGenerate {
      * @throws Exception 异常
      */
     @Override
-    public Map<String, Object> getConfig() throws Exception {
+    public Map<String, Object> getDataModel() throws Exception {
         HashMap<String, Object> config = new HashMap<>();
         // 根包名
         config.put("bussiPackage", CodeConfigProperties.businessPackage);
@@ -136,9 +135,9 @@ public class CodeGenerateOne extends BaseCodeGenerate implements IGenerate {
     @Override
     public List<String> generateCodeFile(String stylePath) throws Exception {
         LOGGER.debug("----jeecg---Code----Generation----[单表模型:" + tableVo.getTableName() + "]------- 生成中。。。");
-        Map<String, Object> config = getConfig();
-        // 配置文件中的 项目目录和模板目录
-        String projectPath = CodeConfigProperties.projectPath;
+        Map<String, Object> dataModel = getDataModel();
+        // 配置文件中的 生成文件路径目录和模板目录
+        String generateRootPath = CodeConfigProperties.projectPath;
         String templatePath = CodeConfigProperties.templatePath;
         // 下面这段判断没啥用,加上反而出错
 //        // 默认模板目录,选择默认样式
@@ -157,7 +156,7 @@ public class CodeGenerateOne extends BaseCodeGenerate implements IGenerate {
         CreateFileConfig createFileConfig = new CreateFileConfig(templatePath);
         createFileConfig.setStylePath(stylePath);
         // 生成代码
-        generate(createFileConfig, projectPath, config);
+        generate(createFileConfig, generateRootPath, dataModel);
         LOGGER.info(" ----- jeecg-boot ---- generate  code  success =======> 表名:" + tableVo.getTableName() + " ");
         return genFileList;
     }
@@ -182,16 +181,16 @@ public class CodeGenerateOne extends BaseCodeGenerate implements IGenerate {
      * 生成代码<br>
      * 指定项目路径、模板路径和模板风格路径<br><br>
      *
-     * @param projectPath 项目路径
+     * @param generateRootPath 项目路径
      * @param templatePath 模板路径
      * @param stylePath 模板风格路径
      * @return 生成代码文件路径
      * @throws Exception 异常
      */
     @Override
-    public List<String> generateCodeFile(String projectPath, String templatePath, String stylePath) throws Exception {
-        if (projectPath != null && !"".equals(projectPath)) {
-            CodeConfigProperties.setProjectPath(projectPath);
+    public List<String> generateCodeFile(String generateRootPath, String templatePath, String stylePath) throws Exception {
+        if (generateRootPath != null && !"".equals(generateRootPath)) {
+            CodeConfigProperties.setProjectPath(generateRootPath);
         }
         if (templatePath != null && !"".equals(templatePath)) {
             CodeConfigProperties.setTemplatePath(templatePath);

+ 2 - 2
tnc-generate/src/main/java/org/jeecg/codegen/generate/impl/CodeGenerateOneToMany.java

@@ -16,7 +16,7 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
      * @throws Exception 异常
      */
     @Override
-    public Map<String, Object> getConfig() throws Exception {
+    public Map<String, Object> getDataModel() throws Exception {
         return null;
     }
 
@@ -31,7 +31,7 @@ public class CodeGenerateOneToMany extends BaseCodeGenerate implements IGenerate
     }
 
     @Override
-    public List<String> generateCodeFile(String var1, String var2, String var3) throws Exception {
+    public List<String> generateCodeFile(String generateRootPath, String var2, String var3) throws Exception {
         return null;
     }
 }

+ 67 - 72
tnc-generate/src/main/java/org/jeecg/codegen/generate/impl/base/BaseCodeGenerate.java

@@ -31,69 +31,74 @@ public class BaseCodeGenerate {
      * 代码生成
      *
      * @param createFileConfig 创建文件配置
-     * @param projectPath 项目路径
-     * @param config 数据项配置
+     * @param generateRootPath 生成文件路径
+     * @param dataModel 数据模型
      * @throws Exception 异常
      */
-    protected void generate(CreateFileConfig createFileConfig, String projectPath, Map<String, Object> config) throws Exception {
-        LOGGER.debug("--------generate----projectPath--------" + projectPath);
-        // 遍历路径生成代码
-        for (int i = 0; i < createFileConfig.getTemplateRootDirs().size(); i++) {
-            generate(projectPath, createFileConfig.getTemplateRootDirs().get(i), config, createFileConfig);
-        }
+    protected void generate(CreateFileConfig createFileConfig, String generateRootPath, Map<String, Object> dataModel) throws Exception {
+        LOGGER.debug("--------generate----generateRootPath--------" + generateRootPath);
+//        // 遍历路径生成代码
+//        for (int i = 0; i < createFileConfig.getTemplateRootDirs().size(); i++) {
+//            generate(generateRootPath, createFileConfig.getTemplateRootDirs().get(i), dataModel, createFileConfig);
+//        }
+        generate(generateRootPath, createFileConfig.getTemplateRootDir(), dataModel, createFileConfig);
     }
 
     /**
      * 代码生成
      *
-     * @param projectPath 项目路径
-     * @param templateRootDir 模板根目录
-     * @param config 配置
+     * @param generateRootPath 生成文件根路径
+     * @param templateRootPath 模板根路径
+     * @param dataModel 数据模型
      * @param createFileConfig 创建文件配置
      * @throws Exception 异常
      */
-    protected void generate(String projectPath, File templateRootDir, Map<String, Object> config, CreateFileConfig createFileConfig) throws Exception {
-        if (templateRootDir == null) {
-            throw new IllegalStateException("'templateRootDir' must be not null");
+    protected void generate(String generateRootPath, File templateRootPath, Map<String, Object> dataModel, CreateFileConfig createFileConfig) throws Exception {
+        if (templateRootPath == null) {
+            throw new IllegalStateException("'templateRootPath' must be not null");
         }
-        LOGGER.info("  load template from templateRootDir = '" + templateRootDir.getAbsolutePath() + "',stylePath ='" + createFileConfig.getStylePath() + "',  out GenerateRootDir:" + CodeConfigProperties.projectPath);
+        LOGGER.info("load template from below config");
+        LOGGER.info("templateRootPath = '" + templateRootPath.getAbsolutePath() + "'");
+        LOGGER.info("stylePath = '" + createFileConfig.getStylePath() + "'");
+        LOGGER.info("out generateRootPath = '" + generateRootPath + "'");
         // 获取要生成的代码模板
-        List<File> fileList = FileHelper.getTemplateFiles(templateRootDir);
-        LOGGER.debug("----srcFiles----size-----------" + fileList.size());
-        LOGGER.debug("----srcFiles----list------------" + fileList);
-        for (File file : fileList) {
-            generate(projectPath, templateRootDir, config, file, createFileConfig);
+        List<File> templateFileList = FileHelper.getTemplateFiles(templateRootPath);
+        LOGGER.debug("----srcFiles----size-----------" + templateFileList.size());
+        LOGGER.debug("----srcFiles----list------------" + templateFileList);
+        for (File templateFile : templateFileList) {
+            generate(generateRootPath, templateRootPath, dataModel, templateFile, createFileConfig);
         }
     }
 
     /**
      * 代码生成
      *
-     * @param projectPath 项目路径
-     * @param templateRootDir 模板根目录
-     * @param config 配置
-     * @param srcFile 模板文件
+     * @param generateRootPath 生成文件根路径
+     * @param templateRootPath 模板根路径
+     * @param dataModel 数据模型
+     * @param templateFile 模板文件
      * @param createFileConfig 创建文件配置
      * @throws Exception 异常
      */
-    protected void generate(String projectPath, File templateRootDir, Map<String, Object> config, File srcFile, CreateFileConfig createFileConfig) throws Exception {
-        LOGGER.debug("-------templateRootDir--" + templateRootDir.getPath());
-        LOGGER.debug("-------srcFile--" + srcFile.getPath());
-        String templateFile = FileHelper.getTemplateFilePath(templateRootDir, srcFile);
+    protected void generate(String generateRootPath, File templateRootPath, Map<String, Object> dataModel, File templateFile, CreateFileConfig createFileConfig) throws Exception {
+        LOGGER.debug("-------templateRootPath--" + templateRootPath.getPath());
+        LOGGER.debug("-------templateFile--" + templateFile.getPath());
+        // 截取模板文件子路径
+        String templateFilePath = FileHelper.getTemplateFilePath(templateRootPath, templateFile);
         try {
-            LOGGER.debug("-------templateFile--" + templateFile);
+            LOGGER.debug("-------templateFilePath--" + templateFilePath);
             // 模板风格未设置,或者是以模板风格开头
-            if (createFileConfig.getStylePath() == null || "".equals(createFileConfig.getStylePath()) || templateFile.replace(File.separator, ".").startsWith(createFileConfig.getStylePath())) {
-                String outputFilepath = getOutputFilepath(config, templateFile, createFileConfig);
-                LOGGER.debug("-------outputFilepath--" + outputFilepath);
-                if (outputFilepath.startsWith("java")) {
-                    String srcFileName = (projectPath + File.separator + CodeConfigProperties.sourceRootPackage.replace(".", File.separator)) + outputFilepath.substring("java".length());
-                    LOGGER.debug("-------java----outputFilepath--" + srcFileName);
-                    generate(templateFile, srcFileName, config, createFileConfig);
+            if (createFileConfig.getStylePath() == null || "".equals(createFileConfig.getStylePath()) || templateFilePath.replace(File.separator, ".").startsWith(createFileConfig.getStylePath())) {
+                String outputFilepath = getOutputFilepath(dataModel, templateFilePath, createFileConfig);
+                LOGGER.debug("-------outputFilePath--" + outputFilepath);
+                if (outputFilepath.startsWith("java")) { // java 文件模板解析
+                    String targetFilePath = generateRootPath + File.separator + CodeConfigProperties.sourceRootPackage.replace(".", File.separator) + outputFilepath.substring("java".length());
+                    LOGGER.debug("-------java----outputFilePath--" + targetFilePath);
+                    generate(createFileConfig.getTemplateRootDir(), templateFilePath, targetFilePath, dataModel);
                 } else if (outputFilepath.startsWith("webapp")) {
-                    String webOutputFilepath = (projectPath + File.separator + CodeConfigProperties.webRootPackage.replace(".", File.separator)) + outputFilepath.substring("webapp".length());
-                    LOGGER.debug("-------webapp---outputFilepath---" + webOutputFilepath);
-                    generate(templateFile, webOutputFilepath, config, createFileConfig);
+                    String targetFilePath = (generateRootPath + File.separator + CodeConfigProperties.webRootPackage.replace(".", File.separator)) + outputFilepath.substring("webapp".length());
+                    LOGGER.debug("-------webapp---outputFilePath---" + targetFilePath);
+                    generate(createFileConfig.getTemplateRootDir(), templateFilePath, targetFilePath, dataModel);
                 }
             }
         } catch (Exception e) {
@@ -104,53 +109,43 @@ public class BaseCodeGenerate {
     /**
      * 代码生成
      *
-     * @param templateRootDir 模板根目录
-     * @param srcFileName 模板文件名
+     * @param templateRootDir 模板根路径
+     * @param templateFilePath 模板文件路径
+     * @param targetFilePath 生成目标文件路径
      * @param config 配置
-     * @param createFileConfig 创建文件配置
      * @throws Exception 异常
      */
-    protected void generate(String templateRootDir, String srcFileName, Map<String, Object> config, CreateFileConfig createFileConfig) throws Exception {
+    protected void generate(File templateRootDir, String templateFilePath, String targetFilePath, Map<String, Object> config) throws Exception {
         // 移除后缀(i)
-        if (srcFileName.endsWith("i")) {
-            srcFileName = srcFileName.substring(0, srcFileName.length() - 1);
+        if (targetFilePath.endsWith("i")) {
+            targetFilePath = targetFilePath.substring(0, targetFilePath.length() - 1);
         }
         // 替换 双下划线(__)为点(.)
-        if (srcFileName.contains(UNDERLINE_2)) {
-            srcFileName = srcFileName.replace(UNDERLINE_2, ".");
+        if (targetFilePath.contains(UNDERLINE_2)) {
+            targetFilePath = targetFilePath.replace(UNDERLINE_2, ".");
         }
         // 统一路径分隔符
-        srcFileName = FileHelper.unifyPath(srcFileName);
+        targetFilePath = FileHelper.unifyPath(targetFilePath);
 
         // 设置模板字符编码
-        Template template = getTemplate(templateRootDir, createFileConfig);
+//        Template template = getTemplate(templateRootDir, createFileConfig);
+//        Template template = FreemarkerHelper.getTemplate(templateRootPathList, templateFilePath);
+        Template template = FreemarkerHelper.getTemplate(templateRootDir, templateFilePath);
         template.setOutputEncoding(StandardCharsets.UTF_8.name());
-        File srcFile = FileHelper.createFile(srcFileName);
-        LOGGER.info("[generate]\t template:" + templateRootDir + " ==> " + srcFileName);
+        File targetFile = FileHelper.createFile(targetFilePath);
+        LOGGER.info("[generate]\t template:" + templateFilePath + " ==> " + targetFilePath);
         // 编译模板生成代码
-        FreemarkerHelper.process(template, config, srcFile);
+        FreemarkerHelper.process(template, config, targetFile);
         // 一多一
-        if (!isOne2Many(srcFile)) {
-            genFileList.add("生成成功:" + FileHelper.unifyPath(srcFileName));
+        if (!isOne2Many(targetFile)) {
+            genFileList.add("生成成功:" + FileHelper.unifyPath(targetFilePath));
         }
         // 一对多
-        if (isOne2Many(srcFile)) {
-            generate(srcFile, "#segment#");
+        if (isOne2Many(targetFile)) {
+            generate(targetFile, "#segment#");
         }
     }
 
-    /**
-     * 获取模板
-     *
-     * @param templateRootDir 模板根目录
-     * @param createFileConfig 创建文件配置
-     * @return 模板
-     * @throws IOException 异常
-     */
-    protected Template getTemplate(String templateRootDir, CreateFileConfig createFileConfig) throws IOException {
-        return FreemarkerHelper.getConfiguration(createFileConfig.getTemplateRootDirs(), templateRootDir).getTemplate(templateRootDir);
-    }
-
     /**
      * 判断是否是一对多
      *
@@ -294,19 +289,19 @@ public class BaseCodeGenerate {
     /**
      * 获取生成文件路径
      *
-     * @param config 模型配置
+     * @param dataModel 数据模型
      * @param templateFile 模板文件路径
      * @param createFileConfig 文件配置
      * @return 生成文件路径
      * @throws Exception 异常
      */
-    protected static String getOutputFilepath(Map<String, Object> config, String templateFile, CreateFileConfig createFileConfig) throws Exception {
+    protected static String getOutputFilepath(Map<String, Object> dataModel, String templateFile, CreateFileConfig createFileConfig) throws Exception {
         String templatePath = templateFile;
         int indexOf = templateFile.indexOf('@');
         if (indexOf != -1) {
             templatePath = templateFile.substring(0, indexOf);
             String substring = templateFile.substring(indexOf + 1);
-            Object obj = config.get(substring);
+            Object obj = dataModel.get(substring);
             if (obj == null) {
                 System.err.println("[not-generate] WARN: test expression is null by key:[" + substring + "] on template:[" + templateFile + "]");
                 return null;
@@ -315,7 +310,7 @@ public class BaseCodeGenerate {
                 return null;
             }
         }
-        String srcFilePath = FreemarkerHelper.getTemplateString(templatePath, config, FreemarkerHelper.getConfiguration(createFileConfig.getTemplateRootDirs()));
+        String srcFilePath = FreemarkerHelper.getTemplateString(templatePath, dataModel, FreemarkerHelper.getConfiguration(createFileConfig.getTemplateRootDir()));
         String stylePath = createFileConfig.getStylePath();
         if (!(stylePath == null || "".equals(stylePath))) {
             srcFilePath = srcFilePath.substring(stylePath.length() + 1);

+ 49 - 41
tnc-generate/src/main/java/org/jeecg/codegen/generate/util/FreemarkerHelper.java

@@ -22,24 +22,17 @@ public class FreemarkerHelper {
     /**
      * 获取freemarker 配置
      *
-     * @param templateRootDirList 模板路径
-     * @param templateRootDir 模板根目录
+     * @param templateRootDir 模板路径
      * @param encoding 编码
      * @return freemarker 配置
      * @throws IOException IO异常
      */
-    public static Configuration getConfiguration(List<File> templateRootDirList, String templateRootDir, String encoding) throws IOException {
+    public static Configuration getConfiguration(File templateRootDir, String encoding) throws IOException {
+        // 默认配置
         Configuration configuration = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
-        LOGGER.debug(" FileTemplateLoader[] size " + templateRootDirList.size());
-        LOGGER.debug(" templateRootDirs templateName " + templateRootDir);
-        FileTemplateLoader[] fileTemplateLoaderArr = new FileTemplateLoader[templateRootDirList.size()];
-        for (int i = 0; i < templateRootDirList.size(); i++) {
-            File file = templateRootDirList.get(i);
-            LOGGER.debug(" FileTemplateLoader " + file.getAbsolutePath());
-            fileTemplateLoaderArr[i] = new FileTemplateLoader(file);
-        }
+        LOGGER.debug(" FileTemplateLoader " + templateRootDir.getAbsolutePath());
         // 加载模板文件
-        configuration.setTemplateLoader(new MultiTemplateLoader(fileTemplateLoaderArr));
+        configuration.setTemplateLoader(new FileTemplateLoader(templateRootDir));
         // 数值格式
         configuration.setNumberFormat("###############");
         // 布尔值格式
@@ -52,38 +45,38 @@ public class FreemarkerHelper {
     /**
      * 获取freemarker 配置
      *
-     * @param templateRootDirList 模板路径
-     * @param templateRootDir 模板根目录
+     * @param templateRootDir 模板路径
      * @return freemarker 配置
      * @throws IOException IO异常
      */
-    public static Configuration getConfiguration(List<File> templateRootDirList, String templateRootDir) throws IOException {
-        return getConfiguration(templateRootDirList, templateRootDir, StandardCharsets.UTF_8.name());
+    public static Configuration getConfiguration(File templateRootDir) throws IOException {
+        return getConfiguration(templateRootDir, StandardCharsets.UTF_8.name());
     }
 
     /**
-     * 获取freemarker 配置
+     * 获取模板
      *
-     * @param templateRootDirList 模板路径
-     * @return freemarker 配置
-     * @throws IOException IO异常
+     * @param templateRootDir 模板根路径
+     * @param templateFilePath 模板路径
+     * @return 模板
+     * @throws IOException 异常
      */
-    public static Configuration getConfiguration(List<File> templateRootDirList) throws IOException {
-        return getConfiguration(templateRootDirList, "/", StandardCharsets.UTF_8.name());
+    public static Template getTemplate(File templateRootDir, String templateFilePath) throws IOException {
+        return getConfiguration(templateRootDir).getTemplate(templateFilePath);
     }
 
     /**
      * 获取模板
      *
      * @param templateFile 模板路径
-     * @param config 配置
+     * @param dataModel 数据模型
      * @param configuration 解析器
      * @return 模板路径
      */
-    public static String getTemplateString(String templateFile, Map<String, Object> config, Configuration configuration) {
+    public static String getTemplateString(String templateFile, Map<String, Object> dataModel, Configuration configuration) {
         StringWriter writer = new StringWriter();
         try {
-            new Template("templateString...", new StringReader(templateFile), configuration).process(config, writer);
+            new Template("templateString...", new StringReader(templateFile), configuration).process(dataModel, writer);
             return writer.toString();
         } catch (Exception e) {
             throw new IllegalStateException("cannot process templateString:" + templateFile + " cause:" + e, e);
@@ -95,13 +88,13 @@ public class FreemarkerHelper {
      *
      * @param template 模板
      * @param config 配置
-     * @param srcFile 模板文件
+     * @param targetFile 生成文件
      * @param encoding 字符编码
      * @throws IOException IO异常
      * @throws TemplateException 模板异常
      */
-    public static void process(Template template, Map<String, Object> config, File srcFile, String encoding) throws IOException, TemplateException {
-        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(srcFile), encoding));
+    public static void process(Template template, Map<String, Object> config, File targetFile, String encoding) throws IOException, TemplateException {
+        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(targetFile), encoding));
         // 向配置中添加格式化工具类
         config.put("Format", new SimpleFormat());
         template.process(config, bufferedWriter);
@@ -113,36 +106,51 @@ public class FreemarkerHelper {
      *
      * @param template 模板
      * @param config 配置
-     * @param srcFile 模板文件
+     * @param targetFile 生成文件
      * @throws IOException IO异常
      * @throws TemplateException 模板异常
      */
-    public static void process(Template template, Map<String, Object> config, File srcFile) throws IOException, TemplateException {
-        process(template, config, srcFile, StandardCharsets.UTF_8.name());
+    public static void process(Template template, Map<String, Object> config, File targetFile) throws IOException, TemplateException {
+        process(template, config, targetFile, StandardCharsets.UTF_8.name());
     }
 
-    public static List<String> m103a(String str, String str2) {
-        String[] b = m100b(str, "\\/");
+    /**
+     * 获取所有路径
+     *
+     * @param parentPath 父级路径
+     * @param subPath 子级路径
+     * @return 所有路径
+     */
+    public static List<String> getAllPath(String parentPath, String subPath) {
+        String[] strList = split(parentPath, "\\/");
         List<String> arrayList = new ArrayList();
-        arrayList.add(str2);
-        arrayList.add(File.separator + str2);
-        String str3 = "";
-        for (int i = 0; i < b.length; i++) {
-            str3 = str3 + File.separator + b[i];
-            arrayList.add(str3 + File.separator + str2);
+        arrayList.add(subPath);
+        arrayList.add(File.separator + subPath);
+        String path = "";
+        for (int i = 0; i < strList.length; i++) {
+            path = path + File.separator + strList[i];
+            arrayList.add(path + File.separator + subPath);
         }
         return arrayList;
     }
 
-    public static String[] m100b(String str, String str2) {
+    /**
+     * 根据分隔符分割字符串
+     *
+     * @param str 被分割的字符串
+     * @param delimiter 分隔符
+     * @return 字符串数组
+     */
+    public static String[] split(String str, String delimiter) {
         if (str == null) {
             return new String[0];
         }
-        StringTokenizer stringTokenizer = new StringTokenizer(str, str2);
+        StringTokenizer stringTokenizer = new StringTokenizer(str, delimiter);
         List<String> arrayList = new ArrayList<>();
         while (stringTokenizer.hasMoreElements()) {
             arrayList.add(stringTokenizer.nextElement().toString());
         }
         return arrayList.toArray(new String[arrayList.size()]);
     }
+
 }

+ 23 - 8
tnc-generate/src/main/java/org/jeecg/codegen/generate/util/SimpleFormat.java

@@ -5,12 +5,21 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 
+/**
+ * 前端使用简单格式化工具
+ */
 public class SimpleFormat {
-    public static String underlineToHump(String para) {
+    /**
+     * 下划线转驼峰
+     *
+     * @param param 参数
+     * @return 结果
+     */
+    public static String underlineToHump(String param) {
         String[] split;
         StringBuilder sb = new StringBuilder();
-        for (String str : para.split("_")) {
-            if (!para.contains("_")) {
+        for (String str : param.split("_")) {
+            if (!param.contains("_")) {
                 sb.append(str);
             } else if (sb.length() == 0) {
                 sb.append(str.toLowerCase());
@@ -22,12 +31,18 @@ public class SimpleFormat {
         return sb.toString();
     }
 
-    public static String humpToUnderline(String para) {
-        StringBuilder sb = new StringBuilder(para);
+    /**
+     * 驼峰转下划线
+     *
+     * @param param 参数
+     * @return 结果
+     */
+    public static String humpToUnderline(String param) {
+        StringBuilder sb = new StringBuilder(param);
         int i = 0;
-        if (!para.contains("_")) {
-            for (int i2 = 0; i2 < para.length(); i2++) {
-                if (Character.isUpperCase(para.charAt(i2))) {
+        if (!param.contains("_")) {
+            for (int i2 = 0; i2 < param.length(); i2++) {
+                if (Character.isUpperCase(param.charAt(i2))) {
                     sb.insert(i2 + i, "_");
                     i++;
                 }

+ 6 - 6
tnc-generate/src/main/java/org/jeecg/codegen/window/JeecgOneUtil.java

@@ -64,8 +64,8 @@ public class JeecgOneUtil {
         tableVo.setFtlDescription("note");
         // 单表代码生成器
         CodeGenerateOne generate = new CodeGenerateOne(tableVo);
-        // 自定义配置 生成代码
-        String projectPath = "D:\\codeGen";
+        // 自定义配置 代码生成路径
+        String generateRootPath = "D:\\codeGen";
         // 代码风格 code,单表只有这一种选择
         String code = "one";
         CgformEnum cgformEnum = CgformEnum.getCgformEnumByConfig(code);
@@ -74,7 +74,7 @@ public class JeecgOneUtil {
         // 风格目录
         String stylePath = cgformEnum.getStylePath();
 
-        List<String> codeFileList = generate.generateCodeFile(projectPath,templatePath,stylePath);
+        List<String> codeFileList = generate.generateCodeFile(generateRootPath,templatePath,stylePath);
 
         for (String fileName : codeFileList) {
             System.out.println(fileName);
@@ -97,14 +97,14 @@ public class JeecgOneUtil {
         tableVo.setFtlDescription("系统用户");
         // 单表代码生成器
         CodeGenerateOne generate = new CodeGenerateOne(tableVo);
-        // 自定义配置 生成代码
-        String projectPath = "D:\\codeGen";
+        // 自定义配置 代码生成路径
+        String generateRootPath = "D:\\codeGen";
         // 模板目录
         String templatePath = "/jeecg/code-template-online";
         // 风格目录
         String stylePath = "default.two";
 
-        List<String> codeFileList = generate.generateCodeFile(projectPath,templatePath,stylePath);
+        List<String> codeFileList = generate.generateCodeFile(generateRootPath,templatePath,stylePath);
 
         for (String fileName : codeFileList) {
             System.out.println(fileName);

+ 3 - 0
tnc-generate/src/main/resources/jeecg/code-template-online/default/two/java/${bussiPackage}/${entityPackage}/vue/${entityName}List.vuei

@@ -5,7 +5,10 @@
     <div class="table-page-search-wrapper">
       <a-form layout="inline" @keyup.enter.native="searchQuery">
         <a-row :gutter="24">
+
+<#-- 查询字段显示个数,超过隐藏 -->
 <#assign query_field_no=0>
+<#-- 查询条件是否显示 是:"Y";否:"N" -->
 <#assign query_flag=false>
 <#assign list_need_dict=false>
 <#assign list_need_category=false>