reflection NSME
This commit is contained in:
parent
335971ce51
commit
329740cc28
@ -11,12 +11,14 @@ import static com.xhpc.pp.utils.security.CP56Time2a.cp56toDate;
|
|||||||
|
|
||||||
public class CacheDataUtils {
|
public class CacheDataUtils {
|
||||||
|
|
||||||
public static Object reflectTranslate(Object srcobj, Class tarclz, Class srcclz, Field[] targetfields) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException {
|
public static Object reflectTranslate(Object srcobj, Class tarclz, Class srcclz, Field[] targetfields) throws IllegalAccessException, InvocationTargetException, InstantiationException {
|
||||||
|
|
||||||
Object tarobj = tarclz.getConstructors()[0].newInstance();
|
Object tarobj = tarclz.getConstructors()[0].newInstance();
|
||||||
for (Field tarfield : targetfields) {
|
for (Field tarfield : targetfields) {
|
||||||
String tarFieldName = tarfield.getName();
|
String tarFieldName = tarfield.getName();
|
||||||
String srcval = (String) srcclz.getMethod("get".concat(capitalize(tarFieldName))).invoke(srcobj);
|
String srcval = null;
|
||||||
|
try {
|
||||||
|
srcval = (String) srcclz.getMethod("get".concat(capitalize(tarFieldName))).invoke(srcobj);
|
||||||
Object tarval;
|
Object tarval;
|
||||||
if (tarfield.getType().getSimpleName().equals("Integer")) {
|
if (tarfield.getType().getSimpleName().equals("Integer")) {
|
||||||
if (srcval.length() == 2) {
|
if (srcval.length() == 2) {
|
||||||
@ -30,6 +32,8 @@ public class CacheDataUtils {
|
|||||||
tarval = srcval;
|
tarval = srcval;
|
||||||
}
|
}
|
||||||
tarclz.getMethod("set".concat(capitalize(tarFieldName)), tarfield.getType()).invoke(tarobj, tarval);
|
tarclz.getMethod("set".concat(capitalize(tarFieldName)), tarfield.getType()).invoke(tarobj, tarval);
|
||||||
|
} catch (NoSuchMethodException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return tarobj;
|
return tarobj;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user