Commit 76059194 authored by yanzg's avatar yanzg

常规BUG的修改

parent a106f9bd
......@@ -289,31 +289,34 @@ public class StringHelper {
* @return 返回获取的值
*/
public static <T> T to(Class<T> cls, Object from) {
if (from == null) {
return null;
}
String vName = cls.getName();
Object to = null;
if (cls.isEnum()) {
String strValue = toString(from);
to = EnumHelper.toEnum(cls, strValue);
} else if (isType(cls, String.class)) {
if (isType(cls, String.class)) {
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);
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);
} 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);
} 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);
} else if (isType(cls, Double.class)) {
to = toDecimal(from);
} else if (isType(cls, Date.class)) {
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;
} else {
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