|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
|
|
import java.beans.IntrospectionException; |
|
|
|
import java.beans.IntrospectionException; |
|
|
|
import java.beans.PropertyDescriptor; |
|
|
|
import java.beans.PropertyDescriptor; |
|
|
|
|
|
|
|
import java.lang.reflect.Constructor; |
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.lang.reflect.InvocationTargetException; |
|
|
|
import java.lang.reflect.InvocationTargetException; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.lang.reflect.Method; |
|
|
@ -208,4 +209,52 @@ public class BeanUtil { |
|
|
|
return fieldObjectMap; |
|
|
|
return fieldObjectMap; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 通过无参数构造函数返回实例 |
|
|
|
|
|
|
|
* @param clazz |
|
|
|
|
|
|
|
* @param <T> |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static <T> T instantiateClass(Class<T> 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 <T> |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static <T> T instantiateClass(Class<T> clazz,Object... params){ |
|
|
|
|
|
|
|
T t = null; |
|
|
|
|
|
|
|
Class[] classes = new Class[params.length]; |
|
|
|
|
|
|
|
for (int i=0;i<params.length;i++){ |
|
|
|
|
|
|
|
classes[i] = params[i].getClass(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Constructor constructor = clazz.getConstructor(classes); |
|
|
|
|
|
|
|
t =(T)constructor.newInstance(params); |
|
|
|
|
|
|
|
} catch (NoSuchMethodException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} catch (IllegalAccessException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} catch (InstantiationException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} catch (InvocationTargetException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return t; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|