本文整理匯總了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;
}
示例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());
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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() + ".");
}
}
}
示例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;
}
示例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));
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
示例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);
}