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;
}
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;
}
相关文章推荐
- java实现压缩、解压缩文件
- java static锁和非static锁区别
- IT十八掌作业_java基础第七天_匿名内部类、异常、包和jar
- java web开发 图片上传功能
- Java常用类源码分析_Calendar类
- java se 多线程下载
- eclipse中不能找到dubbo.xsd报错”cvc-complex-type.2.4.c“的 两种解决方法
- eclipse-failed to load the JNI shared library
- java protected 与默认权限的区别
- 控制小数点后的位数
- 《Java 2 实用教程》读书笔记(四)
- 【Java】封装和继承
- 通过批处理来启动java jar程序
- java ScheduledExecutorService 使用
- Java中整型的缓存机制
- 记录-java(jxl) Excel导入数据库
- 浅谈 java 字符串
- JDK的配置环境
- jvm(1)-走进java
- JAVA实现把指定文件夹下的所有文件压缩成zip包