本文整理汇总了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);
}