當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。