cn.potato.helper.ConvertHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of potato-webmvc Show documentation
Show all versions of potato-webmvc Show documentation
以约定优于配置的思想,结合SpringMVC的一些优点(参数自动注入),实现一个自己的简单MVC框架。
The newest version!
package cn.potato.helper;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
/**
* 转换助手
*
* @author 李恒名
* @since 2016年3月7日
*/
public class ConvertHelper extends Helper{
private ConvertHelper() {}
public static Object convert(Object value,Class>targetType){
return ConvertUtils.convert(value, targetType);
}
public static Object mapConvertToBean(Map map,
Class> beanClass) {
Object bean = null;
try {
bean = beanClass.newInstance();
for (String name : map.keySet()) {
BeanUtils.setProperty(bean, name, map.get(name));
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return bean;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy