Browse Source

jfinal 3.4

James 7 years ago
parent
commit
d224dbfca9

+ 29 - 0
src/main/java/com/jfinal/render/TemplateRender.java

@@ -18,9 +18,11 @@ package com.jfinal.render;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
+import com.jfinal.kit.LogKit;
 import com.jfinal.template.Engine;
 
 /**
@@ -67,6 +69,11 @@ public class TemplateRender extends Render {
 					return ;
 				}
 			}
+			
+			if (outputRenderExceptionToClient) {
+				outputRenderExceptionToClient(e);
+			}
+			
 			throw e;
 		} catch (IOException e) {
 			throw new RenderException(e);
@@ -76,6 +83,28 @@ public class TemplateRender extends Render {
 	public String toString() {
 		return view;
 	}
+	
+	protected static boolean outputRenderExceptionToClient = false;
+	
+	/**
+	 * 设置输出渲染异常到客户端,建议只在开发模式下设置为 true
+	 */
+	public static void setOutputRenderExceptionToClient(boolean outputRenderExceptionToClient) {
+		TemplateRender.outputRenderExceptionToClient = outputRenderExceptionToClient;
+	}
+	
+	/**
+	 * 输出渲染异常到客户端
+	 */
+	protected void outputRenderExceptionToClient(RuntimeException e) {
+		try {
+			OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream());
+			osw.write(e.getMessage());
+			osw.flush();
+		} catch (IOException ioe) {
+			LogKit.logNothing(ioe);
+		}
+	}
 }
 
 

+ 5 - 0
src/main/java/com/jfinal/template/expr/ast/MethodKeyBuilder.java

@@ -87,6 +87,9 @@ public abstract class MethodKeyBuilder {
 					if (type != null) {
 						hash ^= type.getName().hashCode();
 						hash *= HashKit.FNV_PRIME_64;
+					} else {
+						hash ^= "null".hashCode();
+						hash *= HashKit.FNV_PRIME_64;
 					}
 				}
 			}
@@ -110,6 +113,8 @@ public abstract class MethodKeyBuilder {
 					Class<?> type = argTypes[i];
 					if (type != null) {
 						hash = fnv1a64(hash, type.getName());
+					} else {
+						hash = fnv1a64(hash, "null");
 					}
 				}
 			}

+ 3 - 0
src/main/java/com/jfinal/template/expr/ast/SharedMethodKit.java

@@ -156,6 +156,9 @@ public class SharedMethodKit {
 				if (type != null) {
 					hash ^= type.getName().hashCode();
 					hash *= HashKit.FNV_PRIME_64;
+				} else {
+					hash ^= "null".hashCode();
+					hash *= HashKit.FNV_PRIME_64;
 				}
 			}
 		}