|
@ -2,6 +2,7 @@ package io.sc.platform.util; |
|
|
|
|
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
@ -134,4 +135,32 @@ public class ReflectUtil { |
|
|
Method method =clazz.getDeclaredMethod(methodName, innerParameterTypes); |
|
|
Method method =clazz.getDeclaredMethod(methodName, innerParameterTypes); |
|
|
return (T)method.invoke(clazz, parameters); |
|
|
return (T)method.invoke(clazz, parameters); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static Object getFieldValue(Object target, String fieldName) throws IllegalAccessException { |
|
|
|
|
|
if(target==null) { return null; } |
|
|
|
|
|
if(!StringUtils.hasText(fieldName)) { return null; } |
|
|
|
|
|
Field field =null; |
|
|
|
|
|
try{ |
|
|
|
|
|
field =target.getClass().getDeclaredField(fieldName); |
|
|
|
|
|
} catch (NoSuchFieldException e) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
if(field==null) { return null; } |
|
|
|
|
|
field.setAccessible(true); |
|
|
|
|
|
return field.get(target); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void setFieldValue(Object target, String fieldName,Object value) throws IllegalAccessException { |
|
|
|
|
|
if(target==null) { return; } |
|
|
|
|
|
if(!StringUtils.hasText(fieldName)) { return; } |
|
|
|
|
|
Field field =null; |
|
|
|
|
|
try{ |
|
|
|
|
|
field =target.getClass().getDeclaredField(fieldName); |
|
|
|
|
|
} catch (NoSuchFieldException e) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
if(field==null) { return; } |
|
|
|
|
|
field.setAccessible(true); |
|
|
|
|
|
field.set(target,value); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|