diff --git a/src/main/java/com/smallchill/core/base/controller/BladeController.java b/src/main/java/com/smallchill/core/base/controller/BladeController.java
index 093c6466..037d8f8f 100644
--- a/src/main/java/com/smallchill/core/base/controller/BladeController.java
+++ b/src/main/java/com/smallchill/core/base/controller/BladeController.java
@@ -41,7 +41,6 @@ import com.smallchill.core.constant.Cst;
import com.smallchill.core.exception.NoPermissionException;
import com.smallchill.core.exception.NoUserException;
import com.smallchill.core.interfaces.IQuery;
-import com.smallchill.core.modules.support.BeanInjector;
import com.smallchill.core.shiro.ShiroKit;
import com.smallchill.core.toolbox.Func;
import com.smallchill.core.toolbox.Record;
@@ -52,6 +51,7 @@ import com.smallchill.core.toolbox.kit.BeanKit;
import com.smallchill.core.toolbox.kit.LogKit;
import com.smallchill.core.toolbox.kit.StrKit;
import com.smallchill.core.toolbox.log.LogManager;
+import com.smallchill.core.toolbox.support.BeanInjector;
/**
* @author James Zhan, Chill Zhuang
diff --git a/src/main/java/com/smallchill/core/modules/beetl/BeetlMaker.java b/src/main/java/com/smallchill/core/beetl/BeetlMaker.java
similarity index 97%
rename from src/main/java/com/smallchill/core/modules/beetl/BeetlMaker.java
rename to src/main/java/com/smallchill/core/beetl/BeetlMaker.java
index 9f2554b8..74d05aba 100644
--- a/src/main/java/com/smallchill/core/modules/beetl/BeetlMaker.java
+++ b/src/main/java/com/smallchill/core/beetl/BeetlMaker.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.smallchill.core.modules.beetl;
+package com.smallchill.core.beetl;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
diff --git a/src/main/java/com/smallchill/core/modules/beetl/BeetlTemplate.java b/src/main/java/com/smallchill/core/beetl/BeetlTemplate.java
similarity index 87%
rename from src/main/java/com/smallchill/core/modules/beetl/BeetlTemplate.java
rename to src/main/java/com/smallchill/core/beetl/BeetlTemplate.java
index 6357f87a..f042f189 100644
--- a/src/main/java/com/smallchill/core/modules/beetl/BeetlTemplate.java
+++ b/src/main/java/com/smallchill/core/beetl/BeetlTemplate.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.smallchill.core.modules.beetl;
+package com.smallchill.core.beetl;
import java.io.IOException;
import java.io.PrintWriter;
@@ -26,15 +26,15 @@ import org.beetl.core.GroupTemplate;
import org.beetl.core.Template;
import org.beetl.core.resource.StringTemplateResourceLoader;
+import com.smallchill.core.beetl.func.BeetlExt;
+import com.smallchill.core.beetl.func.ShiroExt;
+import com.smallchill.core.beetl.tag.DropDownTag;
+import com.smallchill.core.beetl.tag.FootTag;
+import com.smallchill.core.beetl.tag.HotBlogsTag;
+import com.smallchill.core.beetl.tag.SelectTag;
+import com.smallchill.core.beetl.tag.SideBarTag;
import com.smallchill.core.constant.ConstConfig;
import com.smallchill.core.constant.Cst;
-import com.smallchill.core.modules.beetl.func.BeetlExt;
-import com.smallchill.core.modules.beetl.func.ShiroExt;
-import com.smallchill.core.modules.beetl.tag.DropDownTag;
-import com.smallchill.core.modules.beetl.tag.FootTag;
-import com.smallchill.core.modules.beetl.tag.HotBlogsTag;
-import com.smallchill.core.modules.beetl.tag.SelectTag;
-import com.smallchill.core.modules.beetl.tag.SideBarTag;
/**
* @title Beetl模板绑值
diff --git a/src/main/java/com/smallchill/core/modules/beetl/LowerNameConversion.java b/src/main/java/com/smallchill/core/beetl/LowerNameConversion.java
similarity index 96%
rename from src/main/java/com/smallchill/core/modules/beetl/LowerNameConversion.java
rename to src/main/java/com/smallchill/core/beetl/LowerNameConversion.java
index 2be29d9a..91368443 100644
--- a/src/main/java/com/smallchill/core/modules/beetl/LowerNameConversion.java
+++ b/src/main/java/com/smallchill/core/beetl/LowerNameConversion.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.smallchill.core.modules.beetl;
+package com.smallchill.core.beetl;
import org.beetl.sql.core.NameConversion;
import org.beetl.sql.core.annotatoin.Table;
diff --git a/src/main/java/com/smallchill/core/modules/beetl/MyBeetlGroupUtilConfiguration.java b/src/main/java/com/smallchill/core/beetl/MyBeetlGroupUtilConfiguration.java
similarity index 95%
rename from src/main/java/com/smallchill/core/modules/beetl/MyBeetlGroupUtilConfiguration.java
rename to src/main/java/com/smallchill/core/beetl/MyBeetlGroupUtilConfiguration.java
index 8c722486..2645d490 100644
--- a/src/main/java/com/smallchill/core/modules/beetl/MyBeetlGroupUtilConfiguration.java
+++ b/src/main/java/com/smallchill/core/beetl/MyBeetlGroupUtilConfiguration.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.smallchill.core.modules.beetl;
+package com.smallchill.core.beetl;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
diff --git a/src/main/java/com/smallchill/core/modules/beetl/ReportInterceptor.java b/src/main/java/com/smallchill/core/beetl/ReportInterceptor.java
similarity index 98%
rename from src/main/java/com/smallchill/core/modules/beetl/ReportInterceptor.java
rename to src/main/java/com/smallchill/core/beetl/ReportInterceptor.java
index 87384b6a..1163e7ab 100644
--- a/src/main/java/com/smallchill/core/modules/beetl/ReportInterceptor.java
+++ b/src/main/java/com/smallchill/core/beetl/ReportInterceptor.java
@@ -1,4 +1,4 @@
-package com.smallchill.core.modules.beetl;
+package com.smallchill.core.beetl;
import java.util.List;
diff --git a/src/main/java/com/smallchill/core/modules/beetl/func/BeetlExt.java b/src/main/java/com/smallchill/core/beetl/func/BeetlExt.java
similarity index 99%
rename from src/main/java/com/smallchill/core/modules/beetl/func/BeetlExt.java
rename to src/main/java/com/smallchill/core/beetl/func/BeetlExt.java
index 9532d888..faf7922f 100644
--- a/src/main/java/com/smallchill/core/modules/beetl/func/BeetlExt.java
+++ b/src/main/java/com/smallchill/core/beetl/func/BeetlExt.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.smallchill.core.modules.beetl.func;
+package com.smallchill.core.beetl.func;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
diff --git a/src/main/java/com/smallchill/core/modules/beetl/func/ShiroExt.java b/src/main/java/com/smallchill/core/beetl/func/ShiroExt.java
similarity index 99%
rename from src/main/java/com/smallchill/core/modules/beetl/func/ShiroExt.java
rename to src/main/java/com/smallchill/core/beetl/func/ShiroExt.java
index 7f0457a9..19a09e2f 100644
--- a/src/main/java/com/smallchill/core/modules/beetl/func/ShiroExt.java
+++ b/src/main/java/com/smallchill/core/beetl/func/ShiroExt.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.smallchill.core.modules.beetl.func;
+package com.smallchill.core.beetl.func;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
diff --git a/src/main/java/com/smallchill/core/modules/beetl/tag/DropDownTag.java b/src/main/java/com/smallchill/core/beetl/tag/DropDownTag.java
similarity index 99%
rename from src/main/java/com/smallchill/core/modules/beetl/tag/DropDownTag.java
rename to src/main/java/com/smallchill/core/beetl/tag/DropDownTag.java
index 1c4a3356..7f627dbe 100644
--- a/src/main/java/com/smallchill/core/modules/beetl/tag/DropDownTag.java
+++ b/src/main/java/com/smallchill/core/beetl/tag/DropDownTag.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.smallchill.core.modules.beetl.tag;
+package com.smallchill.core.beetl.tag;
import java.io.IOException;
import java.util.ArrayList;
diff --git a/src/main/java/com/smallchill/core/modules/beetl/tag/FootTag.java b/src/main/java/com/smallchill/core/beetl/tag/FootTag.java
similarity index 98%
rename from src/main/java/com/smallchill/core/modules/beetl/tag/FootTag.java
rename to src/main/java/com/smallchill/core/beetl/tag/FootTag.java
index 6050bdd6..af65dd16 100644
--- a/src/main/java/com/smallchill/core/modules/beetl/tag/FootTag.java
+++ b/src/main/java/com/smallchill/core/beetl/tag/FootTag.java
@@ -1,4 +1,4 @@
-package com.smallchill.core.modules.beetl.tag;
+package com.smallchill.core.beetl.tag;
import java.io.IOException;
import java.util.Map;
diff --git a/src/main/java/com/smallchill/core/modules/beetl/tag/HotBlogsTag.java b/src/main/java/com/smallchill/core/beetl/tag/HotBlogsTag.java
similarity index 89%
rename from src/main/java/com/smallchill/core/modules/beetl/tag/HotBlogsTag.java
rename to src/main/java/com/smallchill/core/beetl/tag/HotBlogsTag.java
index b087df8e..471f4df6 100644
--- a/src/main/java/com/smallchill/core/modules/beetl/tag/HotBlogsTag.java
+++ b/src/main/java/com/smallchill/core/beetl/tag/HotBlogsTag.java
@@ -1,4 +1,4 @@
-package com.smallchill.core.modules.beetl.tag;
+package com.smallchill.core.beetl.tag;
import org.beetl.core.GeneralVarTagBinding;
diff --git a/src/main/java/com/smallchill/core/modules/beetl/tag/SelectTag.java b/src/main/java/com/smallchill/core/beetl/tag/SelectTag.java
similarity index 99%
rename from src/main/java/com/smallchill/core/modules/beetl/tag/SelectTag.java
rename to src/main/java/com/smallchill/core/beetl/tag/SelectTag.java
index e6eb5c59..4efefc1f 100644
--- a/src/main/java/com/smallchill/core/modules/beetl/tag/SelectTag.java
+++ b/src/main/java/com/smallchill/core/beetl/tag/SelectTag.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.smallchill.core.modules.beetl.tag;
+package com.smallchill.core.beetl.tag;
import java.io.IOException;
import java.util.List;
diff --git a/src/main/java/com/smallchill/core/modules/beetl/tag/SideBarTag.java b/src/main/java/com/smallchill/core/beetl/tag/SideBarTag.java
similarity index 99%
rename from src/main/java/com/smallchill/core/modules/beetl/tag/SideBarTag.java
rename to src/main/java/com/smallchill/core/beetl/tag/SideBarTag.java
index 04d7e4a4..da2d79fc 100644
--- a/src/main/java/com/smallchill/core/modules/beetl/tag/SideBarTag.java
+++ b/src/main/java/com/smallchill/core/beetl/tag/SideBarTag.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.smallchill.core.modules.beetl.tag;
+package com.smallchill.core.beetl.tag;
import java.io.IOException;
import java.util.ArrayList;
diff --git a/src/main/java/com/smallchill/core/toolbox/Record.java b/src/main/java/com/smallchill/core/toolbox/Record.java
index 5ec98af1..8e010554 100644
--- a/src/main/java/com/smallchill/core/toolbox/Record.java
+++ b/src/main/java/com/smallchill/core/toolbox/Record.java
@@ -10,8 +10,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
-import com.smallchill.core.modules.support.Conver;
import com.smallchill.core.toolbox.kit.BeanKit;
+import com.smallchill.core.toolbox.support.Conver;
/**
* 扩充了HashMap中的方法
diff --git a/src/main/java/com/smallchill/core/toolbox/ajax/AjaxResult.java b/src/main/java/com/smallchill/core/toolbox/ajax/AjaxResult.java
index e46c5193..5ec729d4 100644
--- a/src/main/java/com/smallchill/core/toolbox/ajax/AjaxResult.java
+++ b/src/main/java/com/smallchill/core/toolbox/ajax/AjaxResult.java
@@ -4,7 +4,7 @@ import com.smallchill.core.toolbox.kit.JsonKit;
public class AjaxResult {
- // 标记成功失败,默认0:成功,1:失败
+ // 返回状态码 (默认0:成功,1:失败)
private int code = 0;
// 返回的中文消息
@@ -40,7 +40,6 @@ public class AjaxResult {
return this;
}
- // 添加成功,用于alertSuccess
public AjaxResult addSuccess(String message) {
this.message = message;
this.code = 0;
@@ -48,7 +47,6 @@ public class AjaxResult {
return this;
}
- // 添加错误,用于alertError
public AjaxResult addError(String message) {
this.message = message;
this.code = 1;
@@ -56,7 +54,6 @@ public class AjaxResult {
return this;
}
- // 添加错误,用于alertFail
public AjaxResult addFail(String message) {
this.message = message;
this.code = 999;
@@ -64,7 +61,6 @@ public class AjaxResult {
return this;
}
- // 添加警告,用于alertWarn
public AjaxResult addWarn(String message) {
this.message = message;
this.code = 2;
@@ -72,14 +68,6 @@ public class AjaxResult {
return this;
}
- /**
- *
- * 封装成功时的数据
- *
- * @param data
- *
- * @return AjaxResult
- */
public AjaxResult success(Object data) {
this.message = "success";
this.data = data;
diff --git a/src/main/java/com/smallchill/core/toolbox/kit/BeanKit.java b/src/main/java/com/smallchill/core/toolbox/kit/BeanKit.java
index 3dd79cb7..3aa93517 100644
--- a/src/main/java/com/smallchill/core/toolbox/kit/BeanKit.java
+++ b/src/main/java/com/smallchill/core/toolbox/kit/BeanKit.java
@@ -9,9 +9,9 @@ import java.util.Map;
import java.util.Map.Entry;
import com.smallchill.core.exception.ToolBoxException;
-import com.smallchill.core.modules.support.Conver;
import com.smallchill.core.toolbox.Func;
import com.smallchill.core.toolbox.Record;
+import com.smallchill.core.toolbox.support.Conver;
/**
* Bean工具类
diff --git a/src/main/java/com/smallchill/core/toolbox/kit/IoKit.java b/src/main/java/com/smallchill/core/toolbox/kit/IoKit.java
index bca88dc2..309964ee 100644
--- a/src/main/java/com/smallchill/core/toolbox/kit/IoKit.java
+++ b/src/main/java/com/smallchill/core/toolbox/kit/IoKit.java
@@ -20,7 +20,7 @@ import java.nio.charset.Charset;
import java.util.Collection;
import com.smallchill.core.exception.ToolBoxException;
-import com.smallchill.core.modules.support.Conver;
+import com.smallchill.core.toolbox.support.Conver;
import com.smallchill.core.toolbox.support.FastByteArrayOutputStream;
import com.smallchill.core.toolbox.support.StreamProgress;
diff --git a/src/main/java/com/smallchill/core/toolbox/kit/ReKit.java b/src/main/java/com/smallchill/core/toolbox/kit/ReKit.java
index 58a625f1..995a5307 100644
--- a/src/main/java/com/smallchill/core/toolbox/kit/ReKit.java
+++ b/src/main/java/com/smallchill/core/toolbox/kit/ReKit.java
@@ -6,7 +6,7 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import com.smallchill.core.modules.support.Conver;
+import com.smallchill.core.toolbox.support.Conver;
import com.smallchill.core.toolbox.support.FieldValidator;
/**
diff --git a/src/main/java/com/smallchill/core/modules/support/BeanInjector.java b/src/main/java/com/smallchill/core/toolbox/support/BeanInjector.java
similarity index 98%
rename from src/main/java/com/smallchill/core/modules/support/BeanInjector.java
rename to src/main/java/com/smallchill/core/toolbox/support/BeanInjector.java
index 9d284f48..06bdd58a 100644
--- a/src/main/java/com/smallchill/core/modules/support/BeanInjector.java
+++ b/src/main/java/com/smallchill/core/toolbox/support/BeanInjector.java
@@ -1,4 +1,4 @@
-package com.smallchill.core.modules.support;
+package com.smallchill.core.toolbox.support;
import java.util.HashMap;
import java.util.Map;
diff --git a/src/main/java/com/smallchill/core/modules/support/Conver.java b/src/main/java/com/smallchill/core/toolbox/support/Conver.java
similarity index 63%
rename from src/main/java/com/smallchill/core/modules/support/Conver.java
rename to src/main/java/com/smallchill/core/toolbox/support/Conver.java
index c05afa6b..afdcab14 100644
--- a/src/main/java/com/smallchill/core/modules/support/Conver.java
+++ b/src/main/java/com/smallchill/core/toolbox/support/Conver.java
@@ -1,7 +1,9 @@
-package com.smallchill.core.modules.support;
+package com.smallchill.core.toolbox.support;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.text.NumberFormat;
import java.util.Date;
import java.util.Set;
@@ -9,7 +11,6 @@ import com.smallchill.core.exception.ToolBoxException;
import com.smallchill.core.toolbox.kit.CollectionKit;
import com.smallchill.core.toolbox.kit.DateTimeKit;
import com.smallchill.core.toolbox.kit.StrKit;
-import com.smallchill.core.toolbox.support.BasicType;
/**
* 类型转换器
@@ -42,23 +43,26 @@ public class Conver {
if(Date.class.isAssignableFrom(clazz)) {
//判断标准日期
- return DateTimeKit.parse(valueStr).toDate();
- } else if(clazz == BigDecimal.class) {
+ return DateTimeKit.parse(valueStr);
+ }else if(clazz == BigInteger.class){
+ //数学计算数字
+ return new BigInteger(valueStr);
+ }else if(clazz == BigDecimal.class) {
//数学计算数字
return new BigDecimal(valueStr);
}else if(clazz == byte[].class) {
//流,由于有字符编码问题,在此使用系统默认
return valueStr.getBytes();
}
-
//未找到可转换的类型,返回原值
return value;
}
}
/**
- * 转换基本类型
- * @param clazz 转换到的类
+ * 转换基本类型
+ * 讲字符串转换为原始类型或包装类型
+ * @param clazz 转换到的类,可以是原始类型类,也可以是包装类型类
* @param valueStr 被转换的字符串
* @return 转换后的对象,如果非基本类型,返回null
*/
@@ -67,6 +71,10 @@ public class Conver {
return null;
}
+ if(clazz.isAssignableFrom(String.class)){
+ return valueStr;
+ }
+
BasicType basicType = null;
try {
basicType = BasicType.valueOf(clazz.getSimpleName().toUpperCase());
@@ -76,8 +84,6 @@ public class Conver {
}
switch (basicType) {
- case STRING:
- return valueStr;
case BYTE:
if(clazz == byte.class) {
return Byte.parseByte(valueStr);
@@ -94,12 +100,12 @@ public class Conver {
return Integer.valueOf(valueStr);
case LONG:
if(clazz == long.class) {
- return Long.parseLong(valueStr);
+ return new BigDecimal(valueStr).longValue();
}
return Long.valueOf(valueStr);
case DOUBLE:
if(clazz == double.class) {
- return Double.parseDouble(valueStr);
+ return new BigDecimal(valueStr).doubleValue();
}
case FLOAT:
if(clazz == float.class) {
@@ -139,6 +145,18 @@ public class Conver {
return value.toString();
}
+ /**
+ * 转换为字符串
+ * 如果给定的值为null,或者转换失败,返回默认值null
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @return 结果
+ */
+ public static String toStr(Object value) {
+ return toStr(value, null);
+ }
+
/**
* 转换为字符
* 如果给定的值为null,或者转换失败,返回默认值
@@ -156,10 +174,145 @@ public class Conver {
return (Character)value;
}
- final String valueStr = value.toString();
- return StrKit.isBlank(valueStr) ? defaultValue : valueStr.charAt(0);
+ final String valueStr = toStr(value, null);
+ return StrKit.isEmpty(valueStr) ? defaultValue : valueStr.charAt(0);
+ }
+
+ /**
+ * 转换为字符
+ * 如果给定的值为null,或者转换失败,返回默认值null
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @return 结果
+ */
+ public static Character toChar(Object value) {
+ return toChar(value, null);
}
+ /**
+ * 转换为byte
+ * 如果给定的值为null,或者转换失败,返回默认值
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @param defaultValue 转换错误时的默认值
+ * @return 结果
+ */
+ public static Byte toByte(Object value, Byte defaultValue) {
+ if (value == null){
+ return defaultValue;
+ }
+ if(value instanceof Byte) {
+ return (Byte)value;
+ }
+ if(value instanceof Number){
+ return ((Number) value).byteValue();
+ }
+ final String valueStr = toStr(value, null);
+ if (StrKit.isBlank(valueStr)){
+ return defaultValue;
+ }
+ try {
+ return Byte.parseByte(valueStr);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ /**
+ * 转换为byte
+ * 如果给定的值为null,或者转换失败,返回默认值null
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @return 结果
+ */
+ public static Byte toByte(Object value) {
+ return toByte(value, null);
+ }
+
+ /**
+ * 转换为Short
+ * 如果给定的值为null,或者转换失败,返回默认值
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @param defaultValue 转换错误时的默认值
+ * @return 结果
+ */
+ public static Short toShort(Object value, Short defaultValue) {
+ if (value == null){
+ return defaultValue;
+ }
+ if(value instanceof Short) {
+ return (Short)value;
+ }
+ if(value instanceof Number){
+ return ((Number) value).shortValue();
+ }
+ final String valueStr = toStr(value, null);
+ if (StrKit.isBlank(valueStr)){
+ return defaultValue;
+ }
+ try {
+ return Short.parseShort(valueStr.trim());
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ /**
+ * 转换为Short
+ * 如果给定的值为null,或者转换失败,返回默认值null
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @return 结果
+ */
+ public static Short toShort(Object value) {
+ return toShort(value, null);
+ }
+
+ /**
+ * 转换为Number
+ * 如果给定的值为空,或者转换失败,返回默认值
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @param defaultValue 转换错误时的默认值
+ * @return 结果
+ */
+ public static Number toNumber(Object value, Number defaultValue) {
+ if (value == null){
+ return defaultValue;
+ }
+ if(value instanceof Number) {
+ return (Number)value;
+ }
+ final String valueStr = toStr(value, null);
+ if (StrKit.isBlank(valueStr)){
+ return defaultValue;
+ }
+ try {
+ return NumberFormat.getInstance().parse(valueStr);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ /**
+ * 转换为Number
+ * 如果给定的值为空,或者转换失败,返回默认值null
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @return 结果
+ */
+ public static Number toNumber(Object value) {
+ return toNumber(value, null);
+ }
+
/**
* 转换为int
* 如果给定的值为空,或者转换失败,返回默认值
@@ -179,7 +332,7 @@ public class Conver {
if(value instanceof Number){
return ((Number) value).intValue();
}
- final String valueStr = value.toString();
+ final String valueStr = toStr(value, null);
if (StrKit.isBlank(valueStr)){
return defaultValue;
}
@@ -191,74 +344,24 @@ public class Conver {
}
/**
- * 转换为byte
- * 如果给定的值为空,或者转换失败,返回默认值
+ * 转换为int
+ * 如果给定的值为null,或者转换失败,返回默认值null
* 转换失败不会报错
*
* @param value 被转换的值
- * @param defaultValue 转换错误时的默认值
* @return 结果
*/
- public static Byte toByte(Object value, Byte defaultValue) {
- if (value == null){
- return defaultValue;
- }
- if(value instanceof Byte) {
- return (Byte)value;
- }
- if(value instanceof Number){
- return ((Number) value).byteValue();
- }
- final String valueStr = value.toString();
- if (StrKit.isBlank(valueStr)){
- return defaultValue;
- }
- try {
- return Byte.parseByte(valueStr);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
- /**
- * 转换为Short
- * 如果给定的值为空,或者转换失败,返回默认值
- * 转换失败不会报错
- *
- * @param value 被转换的值
- * @param defaultValue 转换错误时的默认值
- * @return 结果
- */
- public static Short toShort(Object value, Short defaultValue) {
- if (value == null){
- return defaultValue;
- }
- if(value instanceof Short) {
- return (Short)value;
- }
- if(value instanceof Number){
- return ((Number) value).shortValue();
- }
- final String valueStr = value.toString();
- if (StrKit.isBlank(valueStr)){
- return defaultValue;
- }
- try {
- return Short.parseShort(valueStr.trim());
- } catch (Exception e) {
- return defaultValue;
- }
+ public static Integer toInt(Object value) {
+ return toInt(value, null);
}
/**
* 转换为Integer数组
- * @param
* @param isIgnoreConvertError 是否忽略转换错误,忽略则给值null
* @param values 被转换的值
* @return 结果
*/
- @SafeVarargs
- public static Integer[] toIntArray(boolean isIgnoreConvertError, T... values) {
+ public static Integer[] toIntArray(boolean isIgnoreConvertError, Object... values) {
if(CollectionKit.isEmpty(values)) {
return new Integer[]{};
}
@@ -292,26 +395,37 @@ public class Conver {
if(value instanceof Number){
return ((Number) value).longValue();
}
- final String valueStr = value.toString();
+ final String valueStr = toStr(value, null);
if (StrKit.isBlank(valueStr)){
return defaultValue;
}
try {
+ //支持科学计数法
return new BigDecimal(valueStr.trim()).longValue();
} catch (Exception e) {
return defaultValue;
}
}
+ /**
+ * 转换为long
+ * 如果给定的值为null,或者转换失败,返回默认值null
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @return 结果
+ */
+ public static Long toLong(Object value) {
+ return toLong(value, null);
+ }
+
/**
* 转换为Long数组
- * @param
* @param isIgnoreConvertError 是否忽略转换错误,忽略则给值null
* @param values 被转换的值
* @return 结果
*/
- @SafeVarargs
- public static Long[] toLongArray(boolean isIgnoreConvertError, T... values) {
+ public static Long[] toLongArray(boolean isIgnoreConvertError, Object... values) {
if(CollectionKit.isEmpty(values)) {
return new Long[]{};
}
@@ -345,26 +459,37 @@ public class Conver {
if(value instanceof Number){
return ((Number) value).doubleValue();
}
- final String valueStr = value.toString();
+ final String valueStr = toStr(value, null);
if (StrKit.isBlank(valueStr)){
return defaultValue;
}
try {
+ //支持科学计数法
return new BigDecimal(valueStr.trim()).doubleValue();
} catch (Exception e) {
return defaultValue;
}
}
+ /**
+ * 转换为double
+ * 如果给定的值为空,或者转换失败,返回默认值null
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @return 结果
+ */
+ public static Double toDouble(Object value) {
+ return toDouble(value, null);
+ }
+
/**
* 转换为Double数组
- * @param
* @param isIgnoreConvertError 是否忽略转换错误,忽略则给值null
* @param values 被转换的值
* @return 结果
*/
- @SafeVarargs
- public static Double[] toDoubleArray(boolean isIgnoreConvertError, T... values) {
+ public static Double[] toDoubleArray(boolean isIgnoreConvertError, Object... values) {
if(CollectionKit.isEmpty(values)) {
return new Double[]{};
}
@@ -398,7 +523,7 @@ public class Conver {
if(value instanceof Number){
return ((Number) value).floatValue();
}
- final String valueStr = value.toString();
+ final String valueStr = toStr(value, null);
if (StrKit.isBlank(valueStr)){
return defaultValue;
}
@@ -409,15 +534,25 @@ public class Conver {
}
}
+ /**
+ * 转换为Float
+ * 如果给定的值为空,或者转换失败,返回默认值null
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @return 结果
+ */
+ public static Float toFloat(Object value) {
+ return toFloat(value, null);
+ }
+
/**
* 转换为Float数组
- * @param
* @param isIgnoreConvertError 是否忽略转换错误,忽略则给值null
* @param values 被转换的值
* @return 结果
*/
- @SafeVarargs
- public static Float[] toFloatArray(boolean isIgnoreConvertError, T... values) {
+ public static Float[] toFloatArray(boolean isIgnoreConvertError, Object... values) {
if(CollectionKit.isEmpty(values)) {
return new Float[]{};
}
@@ -448,7 +583,7 @@ public class Conver {
if(value instanceof Boolean) {
return (Boolean)value;
}
- final String valueStr = value.toString();
+ final String valueStr = toStr(value, null);
if (StrKit.isBlank(valueStr)){
return defaultValue;
}
@@ -459,15 +594,25 @@ public class Conver {
}
}
+ /**
+ * 转换为boolean
+ * 如果给定的值为空,或者转换失败,返回默认值null
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @return 结果
+ */
+ public static Boolean toBool(Object value) {
+ return toBool(value, null);
+ }
+
/**
* 转换为Boolean数组
- * @param
* @param isIgnoreConvertError 是否忽略转换错误,忽略则给值null
* @param values 被转换的值
* @return 结果
*/
- @SafeVarargs
- public static Boolean[] toBooleanArray(boolean isIgnoreConvertError, T... values) {
+ public static Boolean[] toBooleanArray(boolean isIgnoreConvertError, Object... values) {
if(CollectionKit.isEmpty(values)) {
return new Boolean[]{};
}
@@ -481,6 +626,135 @@ public class Conver {
}
return bools;
}
+
+ /**
+ * 转换为Enum对象
+ * 如果给定的值为空,或者转换失败,返回默认值
+ * @param clazz Enum的Class
+ * @param value 值
+ * @param defaultValue 默认值
+ * @return Enum
+ */
+ public static > E toEnum(Class clazz, Object value, E defaultValue) {
+ if (value == null){
+ return defaultValue;
+ }
+ if (clazz.isAssignableFrom(value.getClass())) {
+ @SuppressWarnings("unchecked")
+ E myE = (E) value;
+ return myE;
+ }
+ final String valueStr = toStr(value, null);
+ if (StrKit.isBlank(valueStr)){
+ return defaultValue;
+ }
+ try {
+ return Enum.valueOf(clazz,valueStr);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ /**
+ * 转换为Enum对象
+ * 如果给定的值为空,或者转换失败,返回默认值null
+ * @param clazz Enum的Class
+ * @param value 值
+ * @return Enum
+ */
+ public static > E toEnum(Class clazz, Object value) {
+ return toEnum(clazz, value, null);
+ }
+
+ /**
+ * 转换为BigInteger
+ * 如果给定的值为空,或者转换失败,返回默认值
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @param defaultValue 转换错误时的默认值
+ * @return 结果
+ */
+ public static BigInteger toBigInteger(Object value, BigInteger defaultValue) {
+ if (value == null){
+ return defaultValue;
+ }
+ if(value instanceof BigInteger) {
+ return (BigInteger)value;
+ }
+ if(value instanceof Long) {
+ return BigInteger.valueOf((Long)value);
+ }
+ final String valueStr = toStr(value, null);
+ if (StrKit.isBlank(valueStr)){
+ return defaultValue;
+ }
+ try {
+ return new BigInteger(valueStr);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ /**
+ * 转换为BigInteger
+ * 如果给定的值为空,或者转换失败,返回默认值null
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @return 结果
+ */
+ public static BigInteger toBigInteger(Object value) {
+ return toBigInteger(value, null);
+ }
+
+ /**
+ * 转换为BigDecimal
+ * 如果给定的值为空,或者转换失败,返回默认值
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @param defaultValue 转换错误时的默认值
+ * @return 结果
+ */
+ public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue) {
+ if (value == null){
+ return defaultValue;
+ }
+ if(value instanceof BigDecimal) {
+ return (BigDecimal)value;
+ }
+ if(value instanceof Long) {
+ return new BigDecimal((Long)value);
+ }
+ if(value instanceof Double) {
+ return new BigDecimal((Double)value);
+ }
+ if(value instanceof Integer) {
+ return new BigDecimal((Integer)value);
+ }
+ final String valueStr = toStr(value, null);
+ if (StrKit.isBlank(valueStr)){
+ return defaultValue;
+ }
+ try {
+ return new BigDecimal(valueStr);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ /**
+ * 转换为BigDecimal
+ * 如果给定的值为空,或者转换失败,返回默认值
+ * 转换失败不会报错
+ *
+ * @param value 被转换的值
+ * @return 结果
+ */
+ public static BigDecimal toBigDecimal(Object value) {
+ return toBigDecimal(value, null);
+ }
// ----------------------------------------------------------------------- 全角半角转换
/**
diff --git a/src/main/java/com/smallchill/core/modules/support/SpringAcaHolder.java b/src/main/java/com/smallchill/core/toolbox/support/SpringAcaHolder.java
similarity index 97%
rename from src/main/java/com/smallchill/core/modules/support/SpringAcaHolder.java
rename to src/main/java/com/smallchill/core/toolbox/support/SpringAcaHolder.java
index 9dc0f260..50161cb2 100644
--- a/src/main/java/com/smallchill/core/modules/support/SpringAcaHolder.java
+++ b/src/main/java/com/smallchill/core/toolbox/support/SpringAcaHolder.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.smallchill.core.modules.support;
+package com.smallchill.core.toolbox.support;
import java.util.Map;
diff --git a/src/main/java/com/smallchill/system/controller/GenerateController.java b/src/main/java/com/smallchill/system/controller/GenerateController.java
index add776b4..76a87b52 100644
--- a/src/main/java/com/smallchill/system/controller/GenerateController.java
+++ b/src/main/java/com/smallchill/system/controller/GenerateController.java
@@ -16,9 +16,9 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.smallchill.core.base.controller.CurdController;
+import com.smallchill.core.beetl.BeetlMaker;
import com.smallchill.core.constant.Cst;
import com.smallchill.core.interfaces.IMeta;
-import com.smallchill.core.modules.beetl.BeetlMaker;
import com.smallchill.core.plugins.dao.Blade;
import com.smallchill.core.toolbox.Record;
import com.smallchill.core.toolbox.ajax.AjaxResult;
diff --git a/src/main/resources/spring/applicationContext.xml b/src/main/resources/spring/applicationContext.xml
index 55d2a5e6..b795e5d8 100644
--- a/src/main/resources/spring/applicationContext.xml
+++ b/src/main/resources/spring/applicationContext.xml
@@ -10,7 +10,7 @@
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd ">
-
+
@@ -31,7 +31,7 @@
-
+
@@ -52,7 +52,7 @@
-
+
diff --git a/src/test/java/com/smallchill/test/beetlsql/BeetlTest.java b/src/test/java/com/smallchill/test/beetlsql/BeetlTest.java
index ebf95c00..d6300cc2 100644
--- a/src/test/java/com/smallchill/test/beetlsql/BeetlTest.java
+++ b/src/test/java/com/smallchill/test/beetlsql/BeetlTest.java
@@ -11,7 +11,7 @@ import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.db.MySqlStyle;
import org.junit.Test;
-import com.smallchill.core.modules.beetl.ReportInterceptor;
+import com.smallchill.core.beetl.ReportInterceptor;
import com.smallchill.platform.model.Notice;
public class BeetlTest {