public final static void copyProperties(Object from, Object to) {

        Set<Field> fromSet = getAllFiled(from.getClass());
        Set<Field> toSet = getAllFiled(to.getClass());

        Map<String, Field> toMap = new HashMap<String, Field>();
        for (Field f : toSet) {
            toMap.put(f.getName(), f);
        }

        for (Field f : fromSet) {
            if (Modifier.isStatic(f.getModifiers())) {
                continue;
            }
            String name = f.getName();
            Field toField = toMap.get(name);
            if (toField == null) {
                continue;
            }

            toField.setAccessible(true);
            f.setAccessible(true);
            try {
                toField.set(to, f.get(from));
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }

    }
public final static void copyProperties ( Object from , Object to ) { Set < Field > fromSet = getAllFiled ( from . getClass ( ) ) ; Set < Field > toSet = getAllFiled ( to . getClass ( ) ) ; Map < String , Field > toMap = new HashMap < String , Field > ( ) ; for ( Field f : toSet ) { toMap . put ( f . getName ( ) , f ) ; } for ( Field f : fromSet ) { if ( Modifier . isStatic ( f . getModifiers ( ) ) ) { continue ; } String name = f . getName ( ) ; Field toField = toMap . get ( name ) ; if ( toField == null ) { continue ; } toField . setAccessible ( true ) ; f . setAccessible ( true ) ; try { toField . set ( to , f . get ( from ) ) ; } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } } }
将from的属性copy到to中

@param from
@param to   下午4:30:58 created by Darwin(Tianxin)