当前位置: 首页>>代码示例>>Java>>正文


Java PropertyUtils.setProperty方法代码示例

本文整理汇总了Java中org.apache.commons.beanutils.PropertyUtils.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyUtils.setProperty方法的具体用法?Java PropertyUtils.setProperty怎么用?Java PropertyUtils.setProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.beanutils.PropertyUtils的用法示例。


在下文中一共展示了PropertyUtils.setProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getInstanceList

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
 * 封装实体
 * 
 * @param cls
 *            实体类
 * @param list
 *            数据查询结果集
 * @return
 */
public static final <E> List<E> getInstanceList(Class<E> cls, ResultSet rs) {
    List<E> resultList = newArrayList();
    try {
        E object = cls.newInstance();
        Field[] fields = cls.getDeclaredFields();
        while (rs.next()) {
            object = cls.newInstance();
            for (int i = 0; i < fields.length; i++) {
                String fieldName = fields[i].getName();
                PropertyUtils.setProperty(object, fieldName, rs.getObject(fieldName));
            }
            resultList.add(object);
        }
    } catch (Exception e) {
        throw new InstanceException(e);
    }
    return resultList;
}
 
开发者ID:guokezheng,项目名称:automat,代码行数:28,代码来源:InstanceUtil.java

示例2: loadData

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
@Override
protected void loadData() {

    initCollections(new String[] { "collectionProperties.review.searchkey" });
    ReviewSearchBean searchBean = new ReviewSearchBean();
    BeanUtils.copyProperties(this, searchBean, new String[] { "articleno" });

    try {
        PropertyUtils.setProperty(searchBean, option, key);
    } catch (Exception e) {
        logger.warn(e.getMessage());
    }

    if (StringUtils.isEmpty(pagination.getSortColumn())) {
        pagination.setSortColumn(TReview.PROP_POSTDATE);
        pagination.setSortOrder("DESC");
    }

    // 总件数设置
    pagination.setPreperties(reviewService.getCount(searchBean));
    searchBean.setPagination(pagination);
    reviewList = reviewService.find(searchBean);
    // Setting number of records in the particular page
    pagination.setPageRecords(reviewList.size());
}
 
开发者ID:luckyyeah,项目名称:YiDu-Novel,代码行数:26,代码来源:ReviewListAction.java

示例3: setSiteOptionProperty

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
public void setSiteOptionProperty(String property, Object value)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    if (PropertyUtils.isWriteable(this, property)) {

        switch (PropertyUtils
                .getPropertyDescriptor(this, property).getPropertyType().getSimpleName()) {
            case OPTION_VALUE_TYPE_BOOLEAN:
                value = Boolean.valueOf(value.toString());
                break;
            case OPTION_VALUE_TYPE_INTEGER:
                value = Integer.parseInt(value.toString());
                break;
            case OPTION_VALUE_TYPE_USERREGISTRATION:
                value = UserRegistration.valueOf(value.toString());
                break;
            default:
                break;
        }
        PropertyUtils.setProperty(this, property, value);
    }
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:22,代码来源:SiteOptions.java

示例4: instanceChildObject

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
private void instanceChildObject(Object obj,String propertyName){
	int pointIndex=propertyName.indexOf(".");
	if(pointIndex==-1){
		return;
	}
	String name=propertyName.substring(0,pointIndex);
	propertyName=propertyName.substring(pointIndex+1);
	try {
		Object instance=PropertyUtils.getProperty(obj, name);
		if(instance!=null){
			instanceChildObject(instance,propertyName);
			return;
		}
		Object targetEntity=new GeneralEntity(name);
		PropertyUtils.setProperty(obj, name, targetEntity);
		instanceChildObject(targetEntity,propertyName);
	} catch (Exception e) {
		throw new RuleException(e);
	}
}
 
开发者ID:youseries,项目名称:urule,代码行数:21,代码来源:PackageServletHandler.java

示例5: getInstanceList

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
 * 封装实体
 * 
 * @param cls 实体类
 * @param list 数据查询结果集
 * @return
 */
public static final <E> List<E> getInstanceList(Class<E> cls, ResultSet rs) {
	List<E> resultList = newArrayList();
	try {
		E object = cls.newInstance();
		Field[] fields = cls.getDeclaredFields();
		while (rs.next()) {
			object = cls.newInstance();
			for (int i = 0; i < fields.length; i++) {
				String fieldName = fields[i].getName();
				PropertyUtils.setProperty(object, fieldName, rs.getObject(fieldName));
			}
			resultList.add(object);
		}
	} catch (Exception e) {
		throw new InstanceException(e);
	}
	return resultList;
}
 
开发者ID:babymm,项目名称:mumu,代码行数:26,代码来源:InstanceUtil.java

示例6: getInstanceList

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
 * 封装实体
 * 
 * @param cls
 *            实体类
 * @param list
 *            数据查询结果集
 * @return
 */
public static final <E> List<E> getInstanceList(Class<E> cls, ResultSet rs) {
	List<E> resultList = newArrayList();
	try {
		E object = cls.newInstance();
		Field[] fields = cls.getDeclaredFields();
		while (rs.next()) {
			object = cls.newInstance();
			for (int i = 0; i < fields.length; i++) {
				String fieldName = fields[i].getName();
				PropertyUtils.setProperty(object, fieldName, rs.getObject(fieldName));
			}
			resultList.add(object);
		}
	} catch (Exception e) {
		throw new InstanceException(e);
	}
	return resultList;
}
 
开发者ID:tb544731152,项目名称:iBase4J,代码行数:28,代码来源:InstanceUtil.java

示例7: getInstanceList

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
 * 封装实体
 *
 * @param cls
 *            实体类
 * @param rs
 *            数据查询结果集
 * @return
 */
public static final <E> List<E> getInstanceList(Class<E> cls, ResultSet rs) {
    List<E> resultList = newArrayList();
    try {
        E object = cls.newInstance();
        Field[] fields = cls.getDeclaredFields();
        while (rs.next()) {
            object = cls.newInstance();
            for (int i = 0; i < fields.length; i++) {
                String fieldName = fields[i].getName();
                PropertyUtils.setProperty(object, fieldName, rs.getObject(fieldName));
            }
            resultList.add(object);
        }
    } catch (Exception e) {
        throw new InstanceException(e);
    }
    return resultList;
}
 
开发者ID:liuxx001,项目名称:bird-java,代码行数:28,代码来源:InstanceHelper.java

示例8: mapEntity

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
public <T> T mapEntity(String source , SearchHit hit , Class<T> clazz) {
	T t = mapEntity(source , clazz) ;
	
	Map<String, HighlightField> highlightFields = hit.getHighlightFields();
	HighlightField highlightNameField = highlightFields.get("title");
	HighlightField contentHightlightField = highlightFields.get("content");
	try {
		if(highlightNameField!=null&&highlightNameField.fragments()!=null){
			PropertyUtils.setProperty(t, "title" , highlightNameField.fragments()[0].string());
		}
		if(contentHightlightField!=null){
			PropertyUtils.setProperty(t, "content" , contentHightlightField.fragments()[0].string());
		}
		PropertyUtils.setProperty(t, "id" , hit.getId());
	} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
		e.printStackTrace();
	} 
	return t;
}
 
开发者ID:uckefu,项目名称:uckefu,代码行数:20,代码来源:UKResultMapper.java

示例9: setProperty

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public void setProperty(String name, Object value) {
    if (bean instanceof Map) {
        if (bean instanceof MultiValueMap) {
            MultiValueMap valueMap = (MultiValueMap) bean;
            valueMap.set(name, value);
            return;
        }
        Map map = (Map) bean;
        map.put(name, value);
        return;
    }
    try {
        PropertyUtils.setProperty(bean, name, value);
    } catch (Exception e) {
        if (log.isWarnEnabled()) {
            log.warn("Property '" + name + "' can't setter for object of " +
                    "type " + bean.getClass().getName() + ".");
        }
    }
}
 
开发者ID:devefx,项目名称:validator-web,代码行数:22,代码来源:BeanReader.java

示例10: getInstanceList

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
 * 封装实体
 *
 * @param cls  实体类
 * @param list 数据查询结果集
 * @return
 */
public static final <E> List<E> getInstanceList(Class<E> cls, ResultSet rs) {
    List<E> resultList = newArrayList();
    try {
        E object = cls.newInstance();
        Field[] fields = cls.getDeclaredFields();
        while (rs.next()) {
            object = cls.newInstance();
            for (int i = 0; i < fields.length; i++) {
                String fieldName = fields[i].getName();
                PropertyUtils.setProperty(object, fieldName, rs.getObject(fieldName));
            }
            resultList.add(object);
        }
    } catch (Exception e) {
        throw new InstanceException(e);
    }
    return resultList;
}
 
开发者ID:ansafari,项目名称:melon,代码行数:26,代码来源:InstanceUtil.java

示例11: decorate

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
@Override
public void decorate(Object bean, String property, Object strategy) {		
	try {
		Object key = PropertyUtils.getProperty(bean, property);		
		if(key != null){
			SysUser sysUser = null;
			if(key instanceof Integer)
				sysUser = sysUserAdvanceService.loadByKey((Integer)key);	
			if(key instanceof String)
				sysUser = sysUserAdvanceService.loadByUnique((String)key);	
			if(sysUser != null)
				PropertyUtils.setProperty(bean, (String)strategy, sysUser.getUsername());				
		}
	} catch (NullPointerException | IllegalAccessException | InvocationTargetException
			| NoSuchMethodException e) {			
		log.error(Exceptions.getStackTraceAsString(e));
	}
}
 
开发者ID:simbest,项目名称:simbest-cores,代码行数:19,代码来源:SysUserDecorator.java

示例12: escape

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
 * 前方一致検索用の文字列をエスケープする.
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 */
private void escape(Object clone, List<String> fields)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    String escapeChar = (String) PropertyUtils.getProperty(clone, "escapeChar");
    String escapeEscapeChar = escapeChar + escapeChar;
    String escapePercent = escapeChar + PERCENT;
    String escapeUnderBar = escapeChar + UNDER_BAR;
    for (String field : fields) {
        Object object = PropertyUtils.getProperty(clone, field);
        if (object != null) {
            String value = String.valueOf(object);
            // エスケープ文字自体を変換
            value = value.replaceAll(escapeChar, escapeEscapeChar);
            // %を変換
            value = value.replaceAll(PERCENT, escapePercent);
            // _を変換
            value = value.replaceAll(UNDER_BAR, escapeUnderBar);

            PropertyUtils.setProperty(clone, field, value);
        }
    }
}
 
开发者ID:otsecbsol,项目名称:linkbinder,代码行数:28,代码来源:BaseDao.java

示例13: initializeSimpleProperty

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
private Object initializeSimpleProperty(Object parentObject, String property, PropertyDescriptor propertyMetaData)
throws Exception
{
	Object propertyValue = null;
	
	//A Regular Property
	propertyValue = PropertyUtils.getProperty(parentObject, property); 
	if(propertyValue == null)
	{
		Object newlyInitialized = propertyMetaData.getPropertyType().newInstance();
		PropertyUtils.setProperty(parentObject, property, newlyInitialized);
		propertyValue = newlyInitialized;
	}		
	
	return propertyValue;
}
 
开发者ID:ZalemSoftware,项目名称:OpenMobster,代码行数:17,代码来源:TestBeanSyntax.java

示例14: mapBean

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
@Override
public void mapBean(Object bean, String beanName, String property, Object value,
                    Map<String, ConversionOptionBO> conversionOption) throws FlatwormParserException {
    try {
        ConversionOptionBO option = conversionOption.get("append");
        if (option != null && "true".equalsIgnoreCase(option.getValue())) {
            Object currentValue = PropertyUtils.getProperty(bean, property);
            if (currentValue != null)
                value = currentValue.toString() + value;
        }
        PropertyUtils.setProperty(bean, property, value);
    } catch (Exception e) {
        log.error("While running set property method for " + beanName + "." + property
                + " with value '" + value + "'", e);
        throw new FlatwormParserException("Setting field " + beanName + "." + property);
    }
}
 
开发者ID:ahenson,项目名称:flatworm,代码行数:18,代码来源:PropertyUtilsMappingStrategy.java

示例15: setRelation

import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
@Override
public void setRelation(Task task, ObjectId projectId, String fieldName) {
	Project project = projectRepository.findOne(projectId, null);
	try {
		PropertyUtils.setProperty(task, fieldName, project);
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
	taskRepository.save(task);
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:11,代码来源:TaskToProjectRepository.java


注:本文中的org.apache.commons.beanutils.PropertyUtils.setProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。