public static Object convertStringToObject(String value, Class<?> toType) { try { return org.apache.commons.beanutils.ConvertUtils.convert(value, toType); } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } }
public static List convertElementPropertyToList(Collection collection, String propertyName) { List list = new ArrayList(); try { for (Iterator localIterator = collection.iterator(); localIterator.hasNext(); ) { Object obj = localIterator.next(); list.add(PropertyUtils.getProperty(obj, propertyName)); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return list; }
/** * 提取集合中的对象的属性(通过getter函数), 组合成List. * * @param collection 来源集合. * @param propertyName 要提取的属性名. */ @SuppressWarnings("unchecked") public static List convertElementPropertyToList( final Collection collection, final String propertyName) { List list = new ArrayList(); try { for (Object obj : collection) { list.add(PropertyUtils.getProperty(obj, propertyName)); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return list; }