protected static FreeMarkerConfigurer getFreeMarkerConfigurer( ApplicationContext applicationContext) { Map<String, Object> freemarkerVariables = new HashMap<String, Object>(); freemarkerVariables.put("xml_escape", "fmXmlEscape"); freemarkerVariables.put("replaceParam", new ReplaceParamTemplateMethod()); freemarkerVariables.put("timeAgo", new TimeAgoTemplateMethod()); freemarkerVariables.putAll(listTemplateMethod(applicationContext)); Properties freemarkerSettings = new Properties(); freemarkerSettings.put("template_update_delay", "1"); freemarkerSettings.put("defaultEncoding", "UTF-8"); FreeMarkerConfigurer configurer = new FreeMarkerConfigurer(); configurer.setTemplateLoaderPath("/WEB-INF/ftl/"); configurer.setFreemarkerVariables(freemarkerVariables); configurer.setFreemarkerSettings(freemarkerSettings); try { configurer.afterPropertiesSet(); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } catch (TemplateException e) { throw new RuntimeException(e.getMessage(), e); } return configurer; }
@Bean(name = "freemarkerConfig") public FreeMarkerConfigurer freemarkerConfig() { FreeMarkerConfigurer configurer = new FreeMarkerConfigurer(); configurer.setTemplateLoaderPath("/WEB-INF/templates/"); Map<String, Object> map = new HashMap<>(); map.put("xml_escape", new XmlEscape()); configurer.setFreemarkerVariables(map); return configurer; }
@Bean public FreeMarkerConfigurer freemarkerConfig() { FreeMarkerConfigurer freemarkerConfig = new FreeMarkerConfigurer(); freemarkerConfig.setTemplateLoaderPath("classpath:/templates"); freemarkerConfig.setDefaultEncoding("UTF-8"); Map<String, Object> freemarkerVariables = new HashMap<>(); freemarkerVariables.put("layout", freemarkerLayoutDirectives()); freemarkerConfig.setFreemarkerVariables(freemarkerVariables); return freemarkerConfig; }