mirror of
https://gitee.com/jzsw-it/yexuejc-base.git
synced 2025-06-06 22:04:04 +08:00
[update] ObjUtil.copy方法优化(即使copy不成功,也不报错,出警告日志)。PR:copy源和目标对象中的属性类型不一致,copy不成功
This commit is contained in:
parent
a260b41fae
commit
667ad26971
@ -8,6 +8,8 @@ import java.lang.reflect.Method;
|
|||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,6 +22,8 @@ import java.util.stream.Collectors;
|
|||||||
* @date 2018/12/28 15:54
|
* @date 2018/12/28 15:54
|
||||||
*/
|
*/
|
||||||
public class ObjUtil {
|
public class ObjUtil {
|
||||||
|
private static Logger log = Logger.getLogger(ObjUtil.class.getName());
|
||||||
|
|
||||||
private ObjUtil() {
|
private ObjUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,7 +303,9 @@ public class ObjUtil {
|
|||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
log.warning(lowerCaseFirstChar(f.getName()) + " field copy failed. " + e);
|
||||||
|
log.log(Level.FINER, lowerCaseFirstChar(f.getName()) +
|
||||||
|
" field copy failed. The exception information is as follows:", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return o;
|
return o;
|
||||||
@ -321,8 +327,9 @@ public class ObjUtil {
|
|||||||
List<Method> getterMethods = getAllGetterMethods(source.getClass(), "get");
|
List<Method> getterMethods = getAllGetterMethods(source.getClass(), "get");
|
||||||
O o = targetClass.getDeclaredConstructor().newInstance();
|
O o = targetClass.getDeclaredConstructor().newInstance();
|
||||||
getterMethods.forEach(method -> {
|
getterMethods.forEach(method -> {
|
||||||
|
|
||||||
|
String fieldName = method.getName().replace("get", "");
|
||||||
try {
|
try {
|
||||||
String fieldName = method.getName().replace("get", "");
|
|
||||||
Object v = method.invoke(source);
|
Object v = method.invoke(source);
|
||||||
if (invokeSetter) {
|
if (invokeSetter) {
|
||||||
try {
|
try {
|
||||||
@ -344,7 +351,9 @@ public class ObjUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
log.warning(lowerCaseFirstChar(fieldName) + " field copy failed. " + e);
|
||||||
|
log.log(Level.FINER, lowerCaseFirstChar(fieldName) +
|
||||||
|
" field copy failed. The exception information is as follows:\n", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return o;
|
return o;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user