我的思维停留在,使用freemarker来将.ftl文件生成静态html页面。今天用到了,来读取xml模板,并生成xml模板。
上代码:
package xxx;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
public freemarkerTest class {
/** 随着类加载而加载的静态代码块 */
static {
//freemarker的配置类
Configuration configuration = new Configuration();
//因为是springBoot项目,指定模板在templates路径下
configuration.setClassForTemplateLoading(configuration.getClass(), "/templates");
try {
//获取模板类
TEMPLATE = configuration.getTemplate("/freemarker.xml", "UTF-8");
} catch (IOException e) {
e.printStackTrace();
LOGGER.warn("模板加载解析异常:" + e);
}
}
//生成xml
public void createXML(){
//给定xml文件输出路径
Writer writer = new FileWriter("E:/demo.xml");