zoukankan      html  css  js  c++  java
  • java bean 合并

    package com.hainabo.mgcmall.util;

    import java.beans.BeanInfo;
    import java.beans.Introspector;
    import java.beans.PropertyDescriptor;

    public class BeanUtils {

    public static <M> void merge(M target, M destination) throws Exception {
    BeanInfo beanInfo = Introspector.getBeanInfo(target.getClass());

    // 遍历所有属性
    for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) {
    // 允许读写
    if (descriptor.getWriteMethod() != null) {
    //Object originalValue = descriptor.getReadMethod().invoke(target);//target中(descriptor)的值
    // Only copy values values where the destination values is null
    //if (originalValue == null) {
    Object defaultValue = descriptor.getReadMethod().invoke(destination);//destination中(descriptor)的值
    if(defaultValue!=null && !"".equals(defaultValue)){
    descriptor.getWriteMethod().invoke(target, defaultValue);//用defaultValue覆盖到target
    }
    //}
    }
    }
    }
    }



    此方法会将 destination中!""&!null 的值覆盖到 target中
  • 相关阅读:
    maven安装和配置
    maven的安装和配置
    mac上pydev
    Android自动化----adb shell,appium,uiautomator2
    Django
    centos操作---搭建环境 安装python
    Linux系统centos中sudo命令不能用----提升权限
    python---numpy
    python-socket
    Le x820 的刷机记录
  • 原文地址:https://www.cnblogs.com/liuq1991/p/7918445.html
Copyright © 2011-2022 走看看