使用DOC方式打开template文件修改,生成转化后冗余代码
try{
//加载需要装填的模板
Template template = null;
//加载模板文件
configure.setClassForTemplateLoading(this.getClass(),"/util");
//设置对象包装器
configure.setObjectWrapper(new DefaultObjectWrapper());
//设置异常处理器
configure.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER);
//定义Template对象,注意模板类型名字与downloadType要一致
template= configure.getTemplate(downloadType + ".xml");
Writer out = null;
File outFile = new File(filePath);
out= new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile),"utf-8"));
template.process(dataMap,out);
outFile.delete();
out.close();
}catch (Exception e) {
e.printStackTrace();
}
错误信息
freemarker.core.ParseException: Encountered "<" at line 3, column 174949 in 2003permit.xml.
Was expecting one of:
<STRING_LITERAL> ...
<RAW_STRING> ...
"false" ...
"true" ...
<INTEGER> ...
<DECIMAL> ...
"." ...
"+" ...
"-" ...
"!" ...
"[" ...
"(" ...
"{" ...
<ID> ...
at freemarker.core.FMParser.generateParseException(FMParser.java:4697)
经查在使用template文件(XML文件)时,使用DOC打开,直接在上面修改,转化时造成很多的冗余
如图所示