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

使用BeanUtils工具包对javabean操作

2011-06-23 20:22 363 查看
使用BeanUtils工具包对javabean操作,需要使用commons-beanutils-1.8.0.jar和commons-logging-1.1.1.jar, commons-logging-api-1.1.1.jar 这些工具包

将这些工具包导入工程中

代码示例:

package cn.itcast.IntroSpector;
import itcast.cn.Reflect.ReflectPoint;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.apache.commons.beanutils.BeanUtils;
public class TestIntroSpector {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
ReflectPoint rp = new ReflectPoint(3, 5);
//使用BeanUtils包操作javabean
System.out.println(BeanUtils.getProperty(rp, "x").getClass().getName());
BeanUtils.setProperty(rp, "x", "9");
System.out.println(rp.getX());
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: