Commit 76059194 authored by yanzg's avatar yanzg

常规BUG的修改

parent a106f9bd
...@@ -289,31 +289,34 @@ public class StringHelper { ...@@ -289,31 +289,34 @@ public class StringHelper {
* @return 返回获取的值 * @return 返回获取的值
*/ */
public static <T> T to(Class<T> cls, Object from) { public static <T> T to(Class<T> cls, Object from) {
if (from == null) {
return null;
}
String vName = cls.getName(); String vName = cls.getName();
Object to = null; Object to = null;
if (cls.isEnum()) { if (isType(cls, String.class)) {
String strValue = toString(from);
to = EnumHelper.toEnum(cls, strValue);
} else if (isType(cls, String.class)) {
to = toString(from); to = toString(from);
} else if (TYPE_BOOL.equals(vName) || isType(cls, Boolean.class)) { } else if (TYPE_BOOL.equals(vName)
|| (isType(cls, Boolean.class) && from != null)) {
String strValue = toString(from); String strValue = toString(from);
to = toBoolean(strValue); to = toBoolean(strValue);
} else if (TYPE_INT.equals(vName) || isType(cls, Integer.class)) { } else if (TYPE_INT.equals(vName)
|| (isType(cls, Integer.class) && from != null)) {
to = toInt(from); to = toInt(from);
} else if (TYPE_DOUBLE.equals(vName) || isType(cls, Double.class)) { } else if (TYPE_DOUBLE.equals(vName) ||
(isType(cls, Double.class) && from != null)) {
to = toDouble(from); to = toDouble(from);
} else if (TYPE_FLOAT.equals(vName) || isType(cls, Float.class)) { } else if (TYPE_FLOAT.equals(vName)
|| (isType(cls, Float.class) && from != null)) {
to = toDouble(from); to = toDouble(from);
} else if (isType(cls, Double.class)) {
to = toDecimal(from);
} else if (isType(cls, Date.class)) { } else if (isType(cls, Date.class)) {
to = DateHelper.getDateTime(from); to = DateHelper.getDateTime(from);
} else if (cls.isEnum()) {
String strValue = toString(from);
if (strValue != null) {
to = EnumHelper.toEnum(cls, strValue);
} }
if (to != null) { }
if (to == null && from == null) {
return null;
} else if (to != null) {
return (T) to; return (T) to;
} else { } else {
if (ObjectHelper.isSub(cls, from.getClass())) { if (ObjectHelper.isSub(cls, from.getClass())) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment