您的位置:首页 > 编程语言 > Java开发

java提交from表单(用于数据字段很多,不用后台手动赋值)

2016-03-08 15:49 330 查看
public static Object convertBenaToBena(Object from,Object to){
try {
BeanInfo beanInfo = Introspector.getBeanInfo(to.getClass());
PropertyDescriptor[] ps = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor p : ps) {
Method getMethod = p.getReadMethod();
Method setMethod = p.getWriteMethod();
try {
if (getMethod != null && setMethod != null) {
Object value = getMethod.invoke(from);
setMethod.invoke(to, value);
}
} catch (Exception e) {
System.err.println("请写get与set方法");
continue;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return to;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: