在我的应用程序中,所有的Freemarker模板都在/templates/ftl/目录下。因此,在应用程序部署期间,我加载了一个名为“one class”的类,它继承了FreemarkerManager,并具有一个方法。
在仅有一个特定情况下,我需要获取来自不同路径(而非/templates/ftl/)的模板。
在这种特定情况下,如何声明第二个目录用于模板加载,同时不破坏所有调用旧路径的现有代码?我是否可以同时拥有两个不同的模板加载起点?
谢谢。
Configuration configuration = super.createConfiguration(servletContext);
configuration.setDirectoryForTemplateLoading(new File("/templates/ftl/"));
这样,当我需要加载模板文件时,只需像这样操作:
ServletContext servletContext = ServletActionContext.getServletContext();
Configuration configFreemarker = (Configuration) servletContext
.getAttribute("freemarker.Configuration");
Template template = configFreemarker.getTemplate("pathToMyTemplate");
在仅有一个特定情况下,我需要获取来自不同路径(而非/templates/ftl/)的模板。
在这种特定情况下,如何声明第二个目录用于模板加载,同时不破坏所有调用旧路径的现有代码?我是否可以同时拥有两个不同的模板加载起点?
谢谢。