root.put("modelMetadata", modelMetadata);
/*
* 使用Configuration实例来加载指定模板
*/
Template template = CONFIG.getTemplate(templateFile);
template.setEncoding(modelMetadata.getEncoding());
/*
* 代码目录与文件
*/
File fileDir = new File(codeFilePath);
if(!fileDir.exists()) {
fileDir.mkdirs();
}
File codeFile = new File(codeFilePath + File.separator + codeFileName);
System.out.println("generate file " + codeFile);
FileOutputStream fos = new FileOutputStream(codeFile);
OutputStreamWriter out = new OutputStreamWriter(fos, modelMetadata.getEncoding());
BufferedWriter bw = new BufferedWriter(out);
/*
* 合并处理数据与模型
*/
template.process(root, bw);
bw.flush();
bw.close();
return codeFile.getAbsolutePath();
} catch (Exception e) {