提交 26df8165 编写于 作者: Z zhourui

增加ScriptObject判断

上级 61a3698d
......@@ -264,8 +264,10 @@ public class ScriptFactory {
}
}
} else {
list.add(PropertyTools.getOrElse(som, JpaObject.DISTINGUISHEDNAME, String.class, ""));
list.add(PropertyTools.getOrElse(o, JpaObject.DISTINGUISHEDNAME, String.class, ""));
}
} else {
list.add(Objects.toString(o, ""));
}
}
return list;
......
......@@ -9,21 +9,27 @@ public class PropertyTools {
@SuppressWarnings("unchecked")
public static <T> T getOrElse(Object bean, String name, Class<T> cls, T defaultObject) throws Exception {
if (null != bean) {
if (PropertyUtils.isReadable(bean, name)) {
try {
// 如果使用PropertyUtils.isReadable那么Nested就会失效,无法获取map类型中的值.
// Object o = PropertyUtils.getNestedProperty(bean, name);
Object o = PropertyUtils.getProperty(bean, name);
if (null != o) {
return (T) o;
}
} else {
Field field = FieldUtils.getField(bean.getClass(), name, true);
if (null != field) {
Object o = FieldUtils.readField(field, bean, true);
if (null != o) {
return (T) o;
}
} catch (NoSuchMethodException e) {
// java.lang.NoSuchMethodException: Unknown property 'abc' on class 'class
// java.lang.Object'
// nothing pass
}
Field field = FieldUtils.getField(bean.getClass(), name, true);
if (null != field) {
Object o = FieldUtils.readField(field, bean, true);
if (null != o) {
return (T) o;
}
}
}
return defaultObject;
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册