Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

输出自定义模板修改建议 #5056

Closed
lin-code-world opened this issue Dec 31, 2022 · 1 comment
Closed

输出自定义模板修改建议 #5056

lin-code-world opened this issue Dec 31, 2022 · 1 comment

Comments

@lin-code-world
Copy link

lin-code-world commented Dec 31, 2022

当前使用版本(必填,否则不予处理)

3.5.3

该问题是如何引起的?(确定最新版也有问题再提!!!)

AbstractTemplateEngine

protected void outputCustomFile(@NotNull List<CustomFile> customFiles, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
      String entityName = tableInfo.getEntityName();
      String parentPath = getPathInfo(OutputFile.parent);
      customFiles.forEach(file -> {
          String filePath = StringUtils.isNotBlank(file.getFilePath()) ? file.getFilePath() : parentPath;
          if (StringUtils.isNotBlank(file.getPackageName())) {
              filePath = filePath + File.separator + file.getPackageName();
          }
          String fileName = filePath + File.separator + entityName + file.getFileName();
          outputFile(new File(fileName), objectMap, file.getTemplatePath(), file.isFileOverride());
      });
  }

1.建议在TableInfo对象里保留一个根据表名转换后的最原始字段名,tableInfo.getEntityName()该返回值已经被entity.formatFileName污染了。比如我要自定义Vo,最终生成的Vo类名会变成TableEntityVo。fileName拼接的时候使用原始的字段名加上自定义后缀。
CustomFile.Builder().fileName("Vo").build()

2.模板路径调用getTemplateFilePath方法,会自动拼接后缀

3.模板路径只有entity可以设置kotlin,其他service、mapper、controller没有

重现步骤(如果有就写完整)

希望可以自定义类名后缀

@lin-code-world lin-code-world changed the title 输出自定义模板文件文件名建议 输出自定义模板修改建议 Dec 31, 2022
@qmdx
Copy link
Member

qmdx commented Aug 2, 2023

请关注版本 3.5.3.2 发布,已支持 a3d7709

@Test
public void testCustomFileByList() {
    // 设置自定义输出文件
    AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
    generator.strategy(strategyConfig().build());
    // 警用默认模板
    generator.template(templateConfig().disable(TemplateType.CONTROLLER).build());
    generator.injection(injectionConfig().customFile(new ArrayList<CustomFile>() {{
        add(new CustomFile.Builder().fileName("DTO.java").templatePath("/templates/dto.java.vm").packageName("dto").build());
        add(new CustomFile.Builder().fileName("VO.java").templatePath("/templates/vo.java.vm").packageName("vo").build());
        // 通过格式化函数添加文件最后缀
        add(new CustomFile.Builder().formatNameFunction(tableInfo -> "Prefix" + tableInfo.getEntityName() + "Suffix")
            .fileName("Controller.java").templatePath("/templates/controller.java.vm").packageName("controller").build());
    }}).build());
    generator.global(globalConfig().build());
    generator.execute();
}

@qmdx qmdx closed this as completed Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants