内省操作JavaBean
来源:互联网 发布:股票日内交易软件 编辑:程序博客网 时间:2024/05/29 19:19
//使用内省操作bean
public class Test01 {
public static void main(String[] args) throws Exception {
//test1();
test2();
}
private static void test1() throws IntrospectionException{
//得到bean的属性
BeanInfo info=Introspector.getBeanInfo(Person.class,Object.class);
PropertyDescriptor[]pds=info.getPropertyDescriptors();
for(PropertyDescriptor pd:pds){
System.out.println(pd.getName());
}
}
private static void test2() throws Exception {
//操作bean的属性
Person person=new Person();
PropertyDescriptor pds=new PropertyDescriptor("name",Person.class);
//得到属性的set方法,为属性赋值
Method method=pds.getWriteMethod();
method.invoke(person, "张三");
//得到属性的get方法
Method m=pds.getReadMethod();
System.out.println(m.invoke(person, null));
//获得属性的类型
System.out.println(pds.getPropertyType());
}
}
public class Test01 {
public static void main(String[] args) throws Exception {
//test1();
test2();
}
private static void test1() throws IntrospectionException{
//得到bean的属性
BeanInfo info=Introspector.getBeanInfo(Person.class,Object.class);
PropertyDescriptor[]pds=info.getPropertyDescriptors();
for(PropertyDescriptor pd:pds){
System.out.println(pd.getName());
}
}
private static void test2() throws Exception {
//操作bean的属性
Person person=new Person();
PropertyDescriptor pds=new PropertyDescriptor("name",Person.class);
//得到属性的set方法,为属性赋值
Method method=pds.getWriteMethod();
method.invoke(person, "张三");
//得到属性的get方法
Method m=pds.getReadMethod();
System.out.println(m.invoke(person, null));
//获得属性的类型
System.out.println(pds.getPropertyType());
}
}
0 0
- 内省操作JavaBean
- 内省.BeanUtils操作JavaBean
- JAVABean的内省操作
- java内省 操作javaBean
- javaBean的内省操作
- javaBean的内省操作
- javaBean的内省操作
- javaBean的内省操作
- JavaBean的内省操作
- 【内省】introspector操作JavaBean
- 内省操作JavaBean
- JavaBean的内省操作
- javabean的内省操作
- JAVABean的内省操作
- 内省操作JavaBean
- 内省操作JavaBean
- 内省操作javabean属性
- javaBean与内省操作
- SQL联合索引 与 单一列的索引
- 【Android】高仿QQ对话框之自定义对话框CustomDialog
- 【OpenCV入门教程之八】线性邻域滤波专场:方框滤波、均值滤波与高斯滤波
- android异步加载图片显示,并且对图片进行缓存实例
- ListView加载网络数据和图片
- 内省操作JavaBean
- Java中字符串中存在空格引发的问题,及解决方法。
- Python对象的深拷贝与浅拷贝
- C#开发 WinForm如何在选项卡中集成加载多个窗体 实现窗体复用(图文)
- 【OpenCV入门教程之九】 非线性滤波专场:中值滤波、双边滤波
- 遗传算法求f(x)=x1^2+x2^2最大值
- java 序列化和反序列化
- 6-2. 字符串字母大小写转换(10)
- nginx学习(1)