Просмотр исходного кода

支持Beetl模板3.2.x版本.

https://github.com/baomidou/mybatis-plus/issues/2961
nieqiurong 4 лет назад
Родитель
Сommit
2839313e7e

+ 1 - 1
build.gradle

@@ -77,7 +77,7 @@ ext {
         //code generator
         //code generator
         "velocity"                   : "org.apache.velocity:velocity-engine-core:2.2",
         "velocity"                   : "org.apache.velocity:velocity-engine-core:2.2",
         "freemarker"                 : "org.freemarker:freemarker:2.3.30",
         "freemarker"                 : "org.freemarker:freemarker:2.3.30",
-        "beetl"                      : "com.ibeetl:beetl:3.1.8.RELEASE",
+        "beetl"                      : "com.ibeetl:beetl:3.2.1.RELEASE",
         "swagger-annotations"        : "io.swagger:swagger-annotations:1.6.2",
         "swagger-annotations"        : "io.swagger:swagger-annotations:1.6.2",
         //cache
         //cache
         "mybatis-ehcache"            : "org.mybatis.caches:mybatis-ehcache:1.2.1",
         "mybatis-ehcache"            : "org.mybatis.caches:mybatis-ehcache:1.2.1",

+ 17 - 1
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/engine/BeetlTemplateEngine.java

@@ -23,6 +23,7 @@ import org.beetl.core.resource.ClasspathResourceLoader;
 
 
 import java.io.FileOutputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.IOException;
+import java.lang.reflect.Method;
 import java.util.Map;
 import java.util.Map;
 
 
 /**
 /**
@@ -33,6 +34,21 @@ import java.util.Map;
  */
  */
 public class BeetlTemplateEngine extends AbstractTemplateEngine {
 public class BeetlTemplateEngine extends AbstractTemplateEngine {
 
 
+    private static Method method;
+
+    static {
+        try {
+            method = GroupTemplate.class.getDeclaredMethod("getTemplate", Object.class);
+        } catch (NoSuchMethodException e) {
+            try {
+                //3.2.x 方法签名修改成了object,其他低版本为string
+                method = GroupTemplate.class.getDeclaredMethod("getTemplate", String.class);
+            } catch (NoSuchMethodException exception) {
+                throw new RuntimeException(exception);
+            }
+        }
+    }
+
     private GroupTemplate groupTemplate;
     private GroupTemplate groupTemplate;
 
 
     @Override
     @Override
@@ -49,7 +65,7 @@ public class BeetlTemplateEngine extends AbstractTemplateEngine {
 
 
     @Override
     @Override
     public void writer(Map<String, Object> objectMap, String templatePath, String outputFile) throws Exception {
     public void writer(Map<String, Object> objectMap, String templatePath, String outputFile) throws Exception {
-        Template template = groupTemplate.getTemplate(templatePath);
+        Template template = (Template) method.invoke(groupTemplate, templatePath);
         try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile)) {
         try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile)) {
             template.binding(objectMap);
             template.binding(objectMap);
             template.renderTo(fileOutputStream);
             template.renderTo(fileOutputStream);