From ec782ee5a99cb107f18addaf2b07d554a153d0aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Thu, 7 Apr 2022 17:45:06 +0800 Subject: [PATCH] v3.14.4 release (^.^)YYa!! --- changes.txt | 1 + .../directive/base/JbootDirectiveBase.java | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/changes.txt b/changes.txt index 8ed7b4046..83ec24bd5 100644 --- a/changes.txt +++ b/changes.txt @@ -1,4 +1,5 @@ jboot v3.14.4: +新增:生产环境忽略模板指令渲染错误的功能,保证其他内容正常渲染 新增:模板错误渲染器 TemplateErrorRender,用于追加模板指令错误内容 新增:是否开启 Controller Action 缓存的开关,方便在不同的场景下进行开启或者关闭 新增:JbootEventManager 可以设置自己的线程池 diff --git a/src/main/java/io/jboot/web/directive/base/JbootDirectiveBase.java b/src/main/java/io/jboot/web/directive/base/JbootDirectiveBase.java index 65f3a1617..fdff7e779 100644 --- a/src/main/java/io/jboot/web/directive/base/JbootDirectiveBase.java +++ b/src/main/java/io/jboot/web/directive/base/JbootDirectiveBase.java @@ -16,12 +16,14 @@ package io.jboot.web.directive.base; import com.jfinal.aop.Aop; +import com.jfinal.log.Log; import com.jfinal.template.Directive; import com.jfinal.template.Env; import com.jfinal.template.TemplateException; import com.jfinal.template.expr.ast.ExprList; import com.jfinal.template.io.Writer; import com.jfinal.template.stat.Scope; +import io.jboot.Jboot; import io.jboot.utils.StrUtil; import java.io.IOException; @@ -34,6 +36,17 @@ */ public abstract class JbootDirectiveBase extends Directive { + private static final Log LOG = Log.getLog(JbootDirectiveBase.class); + + private static boolean devMode = Jboot.isDevMode(); + + public static boolean isDevMode() { + return devMode; + } + + public static void setDevMode(boolean devMode) { + JbootDirectiveBase.devMode = devMode; + } public JbootDirectiveBase() { Aop.inject(this); @@ -51,7 +64,19 @@ public void exec(Env env, Scope scope, Writer writer) { scope = new Scope(scope); scope.getCtrl().setLocalAssignment(); exprList.eval(scope); - onRender(env, scope, writer); + + try { + onRender(env, scope, writer); + } catch (Throwable e) { + if (devMode) { + throw e; + } + // 生产环境下,忽略指令错误渲染 + else { + LOG.error("Template Directive render error!!!", e); + } + } + }