zoukankan      html  css  js  c++  java
  • 复制

         public static boolean copy(Object source, Object to) {  
             try {  
                 BeanInfo sourceBean = Introspector.getBeanInfo(source.getClass(),java.lang.Object.class);  
                 PropertyDescriptor[] sourceProperty = sourceBean.getPropertyDescriptors();  
                 
                 BeanInfo destBean = Introspector.getBeanInfo(to.getClass(),java.lang.Object.class);  
                 PropertyDescriptor[] destProperty = destBean.getPropertyDescriptors();  
                 
                 for (int i = 0; i < sourceProperty.length; i++) {  
                     for (int j = 0; j < destProperty.length; j++) {  
                         if (sourceProperty[i].getName().equals(destProperty[j].getName())) {  
                             destProperty[j].getWriteMethod().invoke(to,sourceProperty[i].getReadMethod().invoke(source));  
                             break;  
                         }  
                     }  
                 }
                 return true;
             } catch (Exception e) {  
                 e.printStackTrace();
                 return false;
             }  
         }
  • 相关阅读:
    WAMPP安装后mysql无法启动
    转:xampp-php5.6下安装memcached.exe
    apache配置多域名多站点记录
    抽象类
    this关键字
    static关键字
    super关键字
    Set
    Map
    List
  • 原文地址:https://www.cnblogs.com/goatherd/p/11584876.html
Copyright © 2011-2022 走看看