public static String evaluateByVelocity(final String template, final Map<String, ?>... placeHolders) throws Exception {
final StringWriter writer = new StringWriter();
try {
Velocity.init();
final VelocityContext context = new VelocityContext();
// context.put("esc", new EscapeTool());
if (placeHolders != null) {
for (final Map plh : placeHolders) {
copyIntoContext(context, plh);
}
}
Velocity.evaluate(context, writer, "LOG", template);
return writer.getBuffer().toString();
} catch (final Exception ex) {
ex.printStackTrace();
throw new Exception(ex);
} finally {
writer.close();
}
}
我正在尝试将此方法转换为freemarker
public static String evaluateByFreemarker(final String template, final Map<String, ?>... placeHolders) throws Exception {
final StringWriter writer = new StringWriter();
try {
// Instantiate an engine through Configuration Class
Configuration cfg = new Configuration();
cfg.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
if (placeHolders != null) {
for (final Map plh : placeHolders) {
plh.put(placeHolders, plh);
}
}
return writer.getBuffer().toString();
} catch (final Exception ex) {
ex.printStackTrace();
throw new Exception(ex);
} finally {
writer.close();
}
}
我对这部分代码感到震惊
Velocity.evaluate(context, writer, "LOG", template);
freemarker中是否有任何内置方法可以替换上面的代码