public static void populate(Object bean, Map properties) throws IllegalAccessException, InvocationTargetException {
// Do nothing unless both arguments have been specified
if ((bean == null) || (properties == null)) {
return;
}
// Loop through the property name/value pairs to be set
Iterator entries = properties.entrySet().iterator();
while (entries.hasNext()) {
// Identify the property name and value(s) to be assigned
Map.Entry entry = (Map.Entry) entries.next();
String name = (String) entry.getKey();
if (name == null) {
continue;
}
char[] del = {'_'};
name = StringUtils.replace(WordUtils.capitalize(name, del), "_", "");
if (name.length() > 1) {
name = name.substring(0,1).toLowerCase() + name.substring(1);
}
// Perform the assignment for this property
BeanUtils.setProperty(bean, name, entry.getValue());
}
}
댓글 없음:
댓글 쓰기