数据不是乱码,模板文件中的中文是乱码,是模板的文件格式不正确造成的;
其他的地方编码设置:
config.setEncoding(Locale.CHINA, "UTF-8");
config.setDirectoryForTemplateLoading(new File(base+"configuration\\template\\jsp"));
//设置模板路径
config.setObjectWrapper(new DefaultObjectWrapper());
Template temp = config.getTemplate("template_entity.ftl");
temp.setEncoding("UTF-8");
temp.setLocale(Locale.CHINA);
System.err.println(temp.getEncoding());
//把包中点转换成“/”,形成目录的路径
String str = "code."+root.get("projectInfo")+"."+root.get("entityPackage");
String dir = base + str.replace(".", "/") + "/";
//设置目标路径,增加目标类的文件名
String path = dir + StrUtil.FirstCap(root.get("class").toString())+".java";
File f = new File(dir);
if( !f.exists() )
f.mkdirs();
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path),"utf-8"));
// OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(path),"UTF-8");
temp.process(root, out);
out.flush();
out.close();