修改变量

master
qi_liang 4 years ago
parent b6fe9cbdae
commit f1792274e7
  1. 24
      panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java

@ -89,29 +89,29 @@ public class BeanUtil {
/**
* 复制属性不为空的复制为空忽略
*/
public static void copyNotNull(Object targer,Object source){
public static void copyNotNull(Object target,Object source){
Class sourceClass = source.getClass();
List<Field> sourcefieldList = getAllField(sourceClass);
Map<String,Field> fieldMap = new HashMap<>(sourcefieldList.size());
sourcefieldList.forEach(field -> {
List<Field> sourceFieldList = getAllField(sourceClass);
Map<String,Field> fieldMap = new HashMap<>(sourceFieldList.size());
sourceFieldList.forEach(field -> {
field.setAccessible(true);
fieldMap.put(field.getName(),field);
});
Class targerClass = targer.getClass();
List<Field> targerFieldList = getAllField(targerClass);
for (Field field:targerFieldList){
Class targetClass = target.getClass();
List<Field> targetFieldList = getAllField(targetClass);
for (Field field:targetFieldList){
field.setAccessible(true);
Field targerField = fieldMap.get(field.getName());
Field targetField = fieldMap.get(field.getName());
//判断类型是否相等
if (targerField!=null&&targerField.getGenericType().toString().equals(field.getGenericType().toString())){
if (targetField!=null&&targetField.getGenericType().toString().equals(field.getGenericType().toString())){
try {
PropertyDescriptor pd = new PropertyDescriptor(targerField.getName(), targerClass);
PropertyDescriptor pd = new PropertyDescriptor(targetField.getName(), targetClass);
//获得写方法
Method setFieldMethod = pd.getWriteMethod();
Object value = targerField.get(source);
Object value = targetField.get(source);
if (value!=null) {
setFieldMethod.invoke(targer, value);
setFieldMethod.invoke(target, value);
}
} catch (IllegalAccessException e) {
e.printStackTrace();

Loading…
Cancel
Save