38142c55e56a3034c93372ad5cfbb5edf0e2eb94.svn-base 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package org.jeecg.modules.online.config.util;
  2. import freemarker.template.Configuration;
  3. import freemarker.template.Template;
  4. import lombok.extern.slf4j.Slf4j;
  5. import java.io.StringWriter;
  6. import java.util.Map;
  7. @Slf4j
  8. public class FreemarkerHelper {
  9. private static Configuration configuration = new Configuration(Configuration.VERSION_2_3_28);
  10. public static String process(String templatePath, String encode, Map<String, Object> data) {
  11. try {
  12. configuration.setDefaultEncoding(encode);
  13. StringWriter write = new StringWriter();
  14. Template template = null;
  15. template = configuration.getTemplate(templatePath, encode);
  16. template.process(data, write);
  17. return write.toString();
  18. } catch (Exception var5) {
  19. log.error(var5.getMessage(), var5);
  20. return var5.toString();
  21. }
  22. }
  23. public static String process(String templatePath, Map<String, Object> data) {
  24. return process(templatePath, "utf-8", data);
  25. }
  26. public static void main(String[] args) {
  27. String var1 = process("org/jeecg/modules/online/config/engine/tableTemplate.ftl", null);
  28. System.out.println(var1);
  29. }
  30. static {
  31. configuration.setNumberFormat("0.#####################");
  32. configuration.setClassForTemplateLoading(FreemarkerHelper.class, "/");
  33. }
  34. }