|
@@ -23,6 +23,7 @@ import org.beetl.core.resource.ClasspathResourceLoader;
|
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -33,6 +34,21 @@ import java.util.Map;
|
|
|
*/
|
|
|
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;
|
|
|
|
|
|
@Override
|
|
@@ -49,7 +65,7 @@ public class BeetlTemplateEngine extends AbstractTemplateEngine {
|
|
|
|
|
|
@Override
|
|
|
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)) {
|
|
|
template.binding(objectMap);
|
|
|
template.renderTo(fileOutputStream);
|