public Object setDate(ResultSet rs,Object o) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IntrospectionException, IllegalArgumentException, InvocationTargetException, SQLException{
Class cs = Class.forName(o.getClass().getName());
Field [] fileds = cs.getDeclaredFields();
for (Field field : fileds) {
PropertyDescriptor pd = new PropertyDescriptor(field.getName(),cs);
//获取所有set方法
Method method = pd.getWriteMethod();
//利用set方法赋值
method.invoke(o,rs.getString(field.getName()));
}
return o;
}
原文:http://www.cnblogs.com/skeek/p/4383466.html