public class MyBeanUtils
extends org.apache.commons.beanutils.BeanUtils {
public static void copyBeanNotNull2Bean(Object databean,Object tobean)throws Exception
{
PropertyDescriptor origDescriptors[] =
PropertyUtils.getPropertyDescriptors(databean);
for (int i = 0; i < origDescriptors.length; i++) {
String name = origDescriptors.getName();
// String type = origDescriptors.getPropertyType().toString();
if ("class".equals(name)) {
continue; // No point in trying to set an object's class
}
if (PropertyUtils.isReadable(databean, name) &&
PropertyUtils.isWriteable(tobean, name)) {
try {
Object value = PropertyUtils.getSimpleProperty(databean, name);
if(value!=null){
copyProperty(tobean, name, value);
}
}
catch (java.lang.IllegalArgumentException ie) {
logger.error(ie,ie); // Should not happen
}
catch (Exception e) {
logger.error(e,e); // Should not happen
}
}
}
}
}