From 32b544672c99c221da230d8074919efc6168a681 Mon Sep 17 00:00:00 2001 From: qi_liang Date: Wed, 14 Aug 2019 08:22:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8F=8D=E5=B0=84=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=AE=9E=E4=BE=8B=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/panda/beans/util/BeanUtil.java | 49 +++++++++++++++++++ .../java/org/panda/beans/entity/SysUser.java | 20 ++++++++ .../org/panda/beans/util/BeanUtilTest.java | 11 +++++ 3 files changed, 80 insertions(+) diff --git a/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java b/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java index 5d79f7d..04888d5 100644 --- a/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java +++ b/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java @@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -208,4 +209,52 @@ public class BeanUtil { return fieldObjectMap; } + /** + * 通过无参数构造函数返回实例 + * @param clazz + * @param + * @return + */ + public static T instantiateClass(Class clazz){ + T t = null; + try { + t = clazz.newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + return t; + } + + /** + * 通过有参数构造函数返回实例 + * @param clazz + * @param params + * @param + * @return + */ + public static T instantiateClass(Class clazz,Object... params){ + T t = null; + Class[] classes = new Class[params.length]; + for (int i=0;i