类名不同的类属性值复制


            toMethod.invoke(to, new Object[] { value });
        }
    }

    /**
     * 从方法数组中获取指定名称的方法
     * 
     * @param methods
     * @param name
     * @return
     */
    public static Method findMethodByName(Method[] methods, String name) {

        for (int j = 0; j < methods.length; j++) {

            if (methods[j].getName().equals(name)) {

                return methods[j];
            }

        }
        return null;
    }

    public static void main(String[] args) {

        PBlackList from = new PBlackList();
        from.setPunTime(new Date());
        
        from.setAppPerName("方贵");
        
        from.setEffect(1);
        
        from.setAppPerNum("10102322");
        
        PBlackList targ = new PBlackList();
        String[] excut = new String[30];
         
        excut[0] = "apppernum";
        
        try {
            
            copyPropertiesExclude(from, targ, excut);

            System.out.println("日期:"+targ.getPunTime()+"-申请人:"+targ.getAppPerName()+"-有效:"+targ.getEffect()+"-编号:"+targ.getAppPerNum());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    
}

你可能感兴趣的:(java开发)