Skip to content

Commit

Permalink
bean属性拷贝时,支持排除字段
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix committed Dec 6, 2015
1 parent fcc555e commit c09440a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/edu/scup/util/BeanUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.apache.commons.beanutils.PropertyUtilsBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeansException;

import java.lang.reflect.InvocationTargetException;

Expand All @@ -27,4 +29,23 @@ public static void copyProperties(Object dest, Object orig, String... propertyNa
}
}
}

/**
* Copy the property values of the given source bean into the given target bean,
* ignoring the given "ignoreProperties".
* <p>Note: The source and target classes do not have to match or even be derived
* from each other, as long as the properties match. Any bean properties that the
* source bean exposes but the target bean does not will silently be ignored.
* <p>This is just a convenience method. For more complex transfer needs,
* consider using a full BeanWrapper.
*
* @param source the source bean
* @param target the target bean
* @param ignoreProperties array of property names to ignore
* @throws BeansException if the copying failed
* @see BeanWrapper
*/
public static void copyPropertiesExclude(Object source, Object target, String... ignoreProperties) throws BeansException {
org.springframework.beans.BeanUtils.copyProperties(source, target, ignoreProperties);
}
}

0 comments on commit c09440a

Please sign in to comment.