修改:模板加载加try catch, 打印出错误文件名

This commit is contained in:
姜阳琳 2021-11-02 12:01:14 +08:00
parent 61b0233918
commit 8f3ccc8435

View File

@ -25,6 +25,8 @@ import com.jfinal.template.Engine;
import com.jfinal.template.Template;
import com.jfinal.template.source.FileSource;
import com.jfinal.template.source.ISource;
import com.jfinal.template.stat.Location;
import com.jfinal.template.stat.ParseException;
import java.io.File;
import java.io.FileFilter;
@ -32,6 +34,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
/**
* SqlKit
@ -54,6 +57,7 @@ public class TplKit {
public static TplKit use(String configName) {
return use(configName, false);
}
public static synchronized TplKit use(String configName, boolean devMode) {
TplKit tplKit = kitMap.get(configName);
if (tplKit == null) {
@ -134,10 +138,15 @@ public class TplKit {
public synchronized void parseTplTemplate() {
Map<String, Template> sqlTemplateMap = new HashMap<String, Template>(512, 0.5F);
for (TplSource ss : tplSourceList) {
Template template = ss.isFile() ? engine.getTemplate(ss.file) : engine.getTemplate(ss.source);
Map<Object, Object> data = new HashMap<Object, Object>();
data.put(SQL_TEMPLATE_MAP_KEY, sqlTemplateMap);
template.renderToString(data);
String fileName = ss.isFile() ? ss.file : ((FileSource) ss.source).getFinalFileName();
try {
Template template = ss.isFile() ? engine.getTemplate(ss.file) : engine.getTemplate(ss.source);
Map<Object, Object> data = new HashMap<>();
data.put(SQL_TEMPLATE_MAP_KEY, sqlTemplateMap);
template.renderToString(data);
} catch (Exception e) {
throw new RuntimeException(String.format("%s parse error", fileName), e);
}
}
this.sqlTemplateMap = sqlTemplateMap;
}