|
|
@@ -16,8 +16,6 @@
|
|
|
|
|
|
package com.jfinal.config;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
import java.util.function.BiFunction;
|
|
|
import java.util.function.Function;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
@@ -38,6 +36,7 @@ import com.jfinal.log.ILogFactory;
|
|
|
import com.jfinal.log.LogManager;
|
|
|
import com.jfinal.proxy.ProxyFactory;
|
|
|
import com.jfinal.proxy.ProxyManager;
|
|
|
+import com.jfinal.render.ErrorRender;
|
|
|
import com.jfinal.render.IRenderFactory;
|
|
|
import com.jfinal.render.RenderManager;
|
|
|
import com.jfinal.render.ViewType;
|
|
|
@@ -299,7 +298,7 @@ final public class Constants {
|
|
|
* @param error404View the error 404 view
|
|
|
*/
|
|
|
public void setError404View(String error404View) {
|
|
|
- errorViewMapping.put(404, error404View);
|
|
|
+ setErrorView(404, error404View);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -307,7 +306,7 @@ final public class Constants {
|
|
|
* @param error500View the error 500 view
|
|
|
*/
|
|
|
public void setError500View(String error500View) {
|
|
|
- errorViewMapping.put(500, error500View);
|
|
|
+ setErrorView(500, error500View);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -315,7 +314,7 @@ final public class Constants {
|
|
|
* @param error401View the error 401 view
|
|
|
*/
|
|
|
public void setError401View(String error401View) {
|
|
|
- errorViewMapping.put(401, error401View);
|
|
|
+ setErrorView(401, error401View);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -323,17 +322,36 @@ final public class Constants {
|
|
|
* @param error403View the error 403 view
|
|
|
*/
|
|
|
public void setError403View(String error403View) {
|
|
|
- errorViewMapping.put(403, error403View);
|
|
|
+ setErrorView(403, error403View);
|
|
|
}
|
|
|
|
|
|
- private Map<Integer, String> errorViewMapping = new HashMap<Integer, String>();
|
|
|
-
|
|
|
public void setErrorView(int errorCode, String errorView) {
|
|
|
- errorViewMapping.put(errorCode, errorView);
|
|
|
+ ErrorRender.setErrorView(errorCode, errorView);
|
|
|
}
|
|
|
|
|
|
+ /* 已挪至 ErrorRender
|
|
|
public String getErrorView(int errorCode) {
|
|
|
return errorViewMapping.get(errorCode);
|
|
|
+ }*/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置返回给客户端的 json 内容。建议使用 Ret 对象生成 json 内容来配置
|
|
|
+ * <pre>
|
|
|
+ * 例如:
|
|
|
+ * 1:me.setErrorJsonContent(404, Ret.fail("404 Not Found").toJson());
|
|
|
+ * 2:me.setErrorJsonContent(500, Ret.fail("500 Internal Server Error").toJson());
|
|
|
+ * </pre>
|
|
|
+ */
|
|
|
+ public void setErrorJsonContent(int errorCode, String errorJsonContent) {
|
|
|
+ ErrorRender.setErrorJsonContent(errorCode, errorJsonContent);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置返回给客户端的 html 内容
|
|
|
+ * 注意:一般使用 setErrorView 指定 html 页面的方式会更方便些
|
|
|
+ */
|
|
|
+ public void setErrorHtmlContent(int errorCode, String errorHtmlContent) {
|
|
|
+ ErrorRender.setErrorHtmlContent(errorCode, errorHtmlContent);
|
|
|
}
|
|
|
|
|
|
public String getBaseDownloadPath() {
|