当前位置: 首页>>代码示例>>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;未经允许,请勿转载。