當前位置: 首頁>>代碼示例>>Java>>正文


Java BeanUtils.copyProperty方法代碼示例

本文整理匯總了Java中org.apache.commons.beanutils.BeanUtils.copyProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java BeanUtils.copyProperty方法的具體用法?Java BeanUtils.copyProperty怎麽用?Java BeanUtils.copyProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.beanutils.BeanUtils的用法示例。


在下文中一共展示了BeanUtils.copyProperty方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: copyProperties

import org.apache.commons.beanutils.BeanUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void copyProperties(Object dest, Object orig) throws IllegalAccessException, InvocationTargetException {
    PropertyDescriptor[] origDescriptors =
            PropertyUtils.getPropertyDescriptors(orig);
    for (PropertyDescriptor origDescriptor : origDescriptors) {
        String name = origDescriptor.getName();
        if ("class".equals(name)) {
            continue; // No point in trying to set an object's class
        }
        if (PropertyUtils.isReadable(orig, name) &&
                PropertyUtils.isWriteable(dest, name)) {


            try {
                Class origPropClass = PropertyUtils.getPropertyType(orig, name);
                Class destPropClass = PropertyUtils.getPropertyType(dest, name);

                if (destPropClass.isAssignableFrom(origPropClass)) {
                    Object value =
                            PropertyUtils.getSimpleProperty(orig, name);
                    BeanUtils.copyProperty(dest, name, value);
                }
            } catch (NoSuchMethodException e) {
                // Should not happen
            }
        }
    }
}
 
開發者ID:nfl,項目名稱:audible,代碼行數:29,代碼來源:TypeSafeCopy.java

示例2: mapResults

import org.apache.commons.beanutils.BeanUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public <R> Iterable<R> mapResults(ResultSet resultSet, final Class<R> clz) throws SQLException,
        InstantiationException, IllegalAccessException, InvocationTargetException {
    Set<String> metadataColumns = extractColumnNames(resultSet);
    List<R> resultsList = new ArrayList<R>();
    boolean resultIsNumber = Number.class.isAssignableFrom(clz);
    while (resultSet.next()) {
        R instance = null;
        if (!resultIsNumber) {
            instance = clz.newInstance();
        }
        for (String columnName : metadataColumns) {
            Object value = resultSet.getObject(columnName);
            if (value != null) {
                log.debug(value.toString());
                if (resultIsNumber) {
                    instance = (R) value;
                    break;
                }
                
                EntityPropertyBinding entityProperty = entityPropertiesResolver.resolveEntityPropertyBindingByStoreMappingName(columnName, clz);
                if (entityProperty != null) {
                    BeanUtils.copyProperty(instance, entityProperty.getNameFullPath(), value);
                }

            }
        }
        resultsList.add(instance);
    }

    return resultsList;
}
 
開發者ID:eHarmony,項目名稱:pho,代碼行數:33,代碼來源:PhoenixProjectedResultMapper.java

示例3: insert

import org.apache.commons.beanutils.BeanUtils; //導入方法依賴的package包/類
@Transactional(propagation = Propagation.REQUIRED)
public Object insert(Object entity) {
	try{
		BeanUtils.setProperty(entity,"projectGroupCode",SecurityContextUtil.getUserAccount().getProjectGroup().getProjectGroupCode());
		BeanUtils.setProperty(entity, "updatedAt", LocalDateTime.now());
		BeanUtils.setProperty(entity, "createdAt", LocalDateTime.now());
		BeanUtils.copyProperty(entity, "user", SecurityContextUtil.getUserAccount().getUsername());
	return getCurrentSession().save(entity);
	}catch(Exception e){
		e.printStackTrace();
		return null;
	}
}
 
開發者ID:hserv,項目名稱:coordinated-entry,代碼行數:14,代碼來源:QueryExecutorImpl.java

示例4: update

import org.apache.commons.beanutils.BeanUtils; //導入方法依賴的package包/類
public Object update(Object entity) {
	try {
		BeanUtils.setProperty(entity, "updatedAt", LocalDateTime.now());
		BeanUtils.copyProperty(entity, "user", SecurityContextUtil.getUserAccount().getUsername());
		getCurrentSession().update(entity);
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
	return null;
}
 
開發者ID:hserv,項目名稱:coordinated-entry,代碼行數:12,代碼來源:QueryExecutorImpl.java

示例5: delete

import org.apache.commons.beanutils.BeanUtils; //導入方法依賴的package包/類
public void delete(Object entity) {		
		try {
			BeanUtils.copyProperty(entity, "user", SecurityContextUtil.getUserAccount().getUsername());
			BeanUtils.copyProperty(entity, "updatedAt", LocalDateTime.now());
			BeanUtils.copyProperty(entity, "deleted",true);
			getCurrentSession().update(entity);
		} catch (Exception e) {
			getCurrentSession().delete(entity);
		}
}
 
開發者ID:hserv,項目名稱:coordinated-entry,代碼行數:11,代碼來源:QueryExecutorImpl.java


注:本文中的org.apache.commons.beanutils.BeanUtils.copyProperty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。