Browse Source

jfinal 3.2 release ^_^

James 8 years ago
parent
commit
48a9a3a295

+ 8 - 6
src/main/java/com/jfinal/template/ext/extensionmethod/StringExt.java

@@ -16,6 +16,8 @@
 
 package com.jfinal.template.ext.extensionmethod;
 
+import com.jfinal.kit.StrKit;
+
 /**
  * 针对 java.lang.String 的扩展方法
  * 
@@ -48,8 +50,8 @@ public class StringExt {
 	 * 中的逻辑不同,后者只要 非 null 并且 length() > 0 即返回 true
 	 */
 	public Boolean toBoolean(String self) {
-		if (self == null) {
-			return Boolean.FALSE;
+		if (StrKit.isBlank(self)) {
+			return null;	// return Boolean.FALSE;
 		}
 		
 		String value = self.trim().toLowerCase();
@@ -63,19 +65,19 @@ public class StringExt {
 	}
 	
 	public Integer toInt(String self) {
-		return self != null ? Integer.parseInt(self) : null;
+		return StrKit.isBlank(self) ? null : Integer.parseInt(self);
 	}
 	
 	public Long toLong(String self) {
-		return self != null ? Long.parseLong(self) : null;
+		return StrKit.isBlank(self) ? null : Long.parseLong(self);
 	}
 	
 	public Float toFloat(String self) {
-		return self != null ? Float.parseFloat(self) : null;
+		return StrKit.isBlank(self) ? null : Float.parseFloat(self);
 	}
 	
 	public Double toDouble(String self) {
-		return self != null ? Double.parseDouble(self) : null;
+		return StrKit.isBlank(self) ? null : Double.parseDouble(self);
 	}
 }