添加mybatis-generate-extend插件
This commit is contained in:
@@ -1,89 +0,0 @@
|
||||
package com.micro.fast.util;
|
||||
|
||||
import freemarker.core.ParseException;
|
||||
import freemarker.template.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 根据freemarker模板生成文件
|
||||
*/
|
||||
public class FreemarkerUtil {
|
||||
|
||||
/**
|
||||
* 加载模板文件所在的目录
|
||||
*/
|
||||
private static final String TEMPLATES_DIR_URL = "templates";
|
||||
|
||||
private static Configuration cfg = null;
|
||||
|
||||
static {
|
||||
if (cfg==null){
|
||||
cfg = new Configuration();
|
||||
}
|
||||
//设置末班文件的加载目录
|
||||
setConfiguration(FreemarkerUtil.TEMPLATES_DIR_URL);
|
||||
}
|
||||
|
||||
private static void setConfiguration(String templatesDirUrl) {
|
||||
|
||||
//1.设置编码
|
||||
cfg.setDefaultEncoding("utf-8");
|
||||
//2.设置加载模板文件的位置
|
||||
String classPath = FreemarkerUtil.class.getResource("/"+templatesDirUrl).getPath();
|
||||
try {
|
||||
cfg.setDirectoryForTemplateLoading(new File(classPath));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean createFile(String templateName, Map<String, Object> data, String targetFileName) {
|
||||
Template template = null;
|
||||
Writer out = null;
|
||||
//1.获取classpath路径
|
||||
String classPath = FreemarkerUtil.class.getResource("/").getPath();
|
||||
//2.如果目标文件存在就先删除目标文件
|
||||
File targetFile = new File(classPath + targetFileName);
|
||||
if (targetFile.exists()){
|
||||
targetFile.delete();
|
||||
}
|
||||
try {
|
||||
//3.获取模板文件对象
|
||||
template = cfg.getTemplate(templateName);
|
||||
//4.获取输出流对象
|
||||
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(classPath+targetFileName)));
|
||||
//5.向模板对象中填充数据生成文件
|
||||
template.process(data,out);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (MalformedTemplateNameException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (TemplateException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//创建成功
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user