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;
}
时间: 2024-10-05 22:09:03