Browse Source

Merge branch 'master' into glx

master
glx 1 month ago
parent
commit
29056714eb
  1. 18
      src/main/java/com/youlai/boot/codegen/freemarker/CustomFreemarkerTemplateEngine.java

18
src/main/java/com/youlai/boot/codegen/freemarker/CustomFreemarkerTemplateEngine.java

@ -13,12 +13,12 @@ public class CustomFreemarkerTemplateEngine extends AbstractTemplateEngine {
private final Configuration cfg = new Configuration(Configuration.VERSION_2_3_34);
/**
* 模板基础路径核心
* 模板基础路径核心
*/
private final String templateBasePath;
/**
* 构造器注入你想要的方式
* 构造器注入你想要的方式
*/
public CustomFreemarkerTemplateEngine(String templateBasePath) {
if (templateBasePath.endsWith("/")) {
@ -48,13 +48,25 @@ public class CustomFreemarkerTemplateEngine extends AbstractTemplateEngine {
File outputFile) throws Exception {
// MP 默认带 /templates/
String fileName = outputFile.getName();
// 关键:控制不覆盖 mapper / xml
if (fileName.endsWith("Mapper.java") ||
fileName.endsWith("Mapper.xml")) {
if (outputFile.exists()) {
System.out.println(">>> 已存在,跳过生成: " + outputFile.getAbsolutePath());
return;
}
}
// entity 允许覆盖(不拦截)
String realTemplate = templatePath;
if (realTemplate.startsWith("/templates/")) {
realTemplate = realTemplate.substring("/templates/".length());
}
// ⭐ 拼接最终路径
String finalTemplate = templateBasePath + realTemplate + ".ftl";
Template template = cfg.getTemplate(finalTemplate);

Loading…
Cancel
Save