PropertyDescriptor 描述了一个JavaBean 属性的一对访问方法即 getter和setter。 常用的构造方法是PropertyDescriptor(String propertyName,Class<? // bean的实例 Form form = new PropertyDescriptorDemo().new Form(); // 创建属性name 的PropertyDescriptor PropertyDescriptor pd = new PropertyDescriptor("name", form.getClass()); // 获取属性的setter <init>(PropertyDescriptor.java:110) at java.beans.PropertyDescriptor.
PropertyDescriptor 详解](http://blog.csdn.net/z69183787/article/details/8443777) ---- 转自 http://blog.csdn.net package com.zhoushun; import java.lang.reflect.Method; import java.lang.reflect.Field; import java.beans.PropertyDescriptor ; public class PropertyUtil { @SuppressWarnings("unchecked") public static PropertyDescriptor getPropertyDescriptor void setProperty(Object obj,String propertyName,Object value){ Class clazz = obj.getClass();//获取对象的类型 PropertyDescriptor static Object getProperty(Object obj, String propertyName){ Class clazz = obj.getClass();//获取对象的类型 PropertyDescriptor
结构 java.beans 类 PropertyDescriptor java.lang.Object java.beans.FeatureDescriptor java.beans.PropertyDescriptor 直接已知子类: IndexedPropertyDescriptor 描述 public class PropertyDescriptor extends FeatureDescriptor PropertyDescriptor 构造方法 1、public PropertyDescriptor(String propertyName, Class<? 2、public PropertyDescriptor(String propertyName, Class<? 如果读取、写入、属性类型、属性编辑器和标记都是等同的,则两个PropertyDescriptor 是相同的。 覆盖:类 Object 中的 equals 参数:obj – 要与之比较的引用对象。
一、jdk中类PropertyDescriptor获取 jdk中Introspector类为工具提供了一种标准的方法来了解目标Java Bean支持的属性、事件和方法。 java.beans.Introspector#getTargetPropertyInfo private PropertyDescriptor[] getTargetPropertyInfo() { > resultType = method.getReturnType(); int argCount = argTypes.length; PropertyDescriptor pd = null; [] propertyDescriptors = beanInfo.getPropertyDescriptors(); for(PropertyDescriptor propertyDescriptor (继承父类的Object) 、setService12123会生成PropertyDescriptor且具有写方法 存在问题: 方法有返回值、且静态的方法是不具备生成PropertyDescriptor
1构造方法 通过调用 getFoo 和 setFoo 存取方法,为符合标准 Java 约定的属性构造一个PropertyDescriptor public PropertyDescriptor( > beanClass) 该构造函数使用简单属性的名称,以及读取和写入属性的方法名称 public PropertyDescriptor(String propertyName, Class<? public PropertyDescriptor(String propertyName, Method readMethod, Method writeMethod) 测试 @Test public void show() throws Exception { Class clazz = UserInfo.class; PropertyDescriptor p = new PropertyDescriptor ("name", clazz); System.out.println("显示属性描述类:" + p); } 显示属性描述类: java.beans.PropertyDescriptor[
一、软件包 java.beans 包含与开发 beans 有关的类,即基于 JavaBeansTM 架构的组件 二、PropertyDescriptor PropertyDescriptor 描述 Java Bean 通过一对存储器方法导出的一个属性 public class PropertyDescriptor extends FeatureDescriptor { //构造方法 //通过调用 getFoo 和 setFoo 存取方法,为符合标准 Java 约定的属性构造一个 PropertyDescriptor public PropertyDescriptor(String pd = new PropertyDescriptor(propertyName,obj.getClass()); Method setMethod = pd.getWriteMethod(); */ public interface BeanInfo { //获得 beans PropertyDescriptor PropertyDescriptor[] getPropertyDescriptors
package com.zhoushun; import java.lang.reflect.Method; import java.lang.reflect.Field; import java.beans.PropertyDescriptor ; public class PropertyUtil { @SuppressWarnings("unchecked") public static PropertyDescriptor getPropertyDescriptor error".equals(fieldNameGet)) { PropertyDescriptor pd = new PropertyDescriptor pd1 = new PropertyDescriptor(fieldName, objSet.getClass()); Method setMethod = pd1 实际情况中需要判断下他的参数类型 } //读数据 for(Field f : fields) { PropertyDescriptor pd = new PropertyDescriptor
本文首发于本博客 猫叔的博客,转载请申明出处 前言 感谢GY丶L粉丝的提问:属性描述器PropertyDescriptor是干嘛用的? 本来我也没有仔细了解过描述符这一块的知识,不过粉丝问了,我就抽周末的时间看看,顺便学习一下,粉丝问的刚好是PropertyDescriptor这个属性描述符,我看了下源码。 /** * A PropertyDescriptor describes one property that a Java Bean * exports via a pair of accessor PropertyDescriptor 那么我们大致知道了FeatureDescriptor,接下来就可以来深入了解看看这个属性描述符PropertyDescriptor。 说到属性,大家一定会想到的就是get/set这个些基础的东西,当我打开PropertyDescriptor源码的时候,我也看到了一开始猜想的点。
: MemberDescriptor J# /** @attribute ComVisibleAttribute(true) */ public abstract class PropertyDescriptor extends MemberDescriptor JScript ComVisibleAttribute(true) public abstract class PropertyDescriptor PropertyDescriptor 提供以下属性和方法: Converter 包含此属性的 TypeConverter。 IsLocalizable 指示该属性是否应该本地化。 PropertyDescriptor 还提供以下 abstract 属性和方法: ComponentType 包含该属性绑定到的组件的类型。 System.ComponentModel.PropertyDescriptor myProperty = properties.Find("Text", false); // Prints the
本文首发于本博客 猫叔的博客,转载请申明出处 前言 感谢GY丶L粉丝的提问:属性描述器PropertyDescriptor是干嘛用的? 本来我也没有仔细了解过描述符这一块的知识,不过粉丝问了,我就抽周末的时间看看,顺便学习一下,粉丝问的刚好是PropertyDescriptor这个属性描述符,我看了下源码。 /** * A PropertyDescriptor describes one property that a Java Bean * exports via a pair of accessor PropertyDescriptor 那么我们大致知道了FeatureDescriptor,接下来就可以来深入了解看看这个属性描述符PropertyDescriptor。 说到属性,大家一定会想到的就是get/set这个些基础的东西,当我打开PropertyDescriptor源码的时候,我也看到了一开始猜想的点。
ReturnData(); User obj = new User (); obj .setCustId(1L); rd .setObj( obj ); PropertyDescriptor descriptor = new PropertyDescriptor(“custId“, rd.getObj().getClass());//红色是属性名 Method readMethod PropertyDescriptor类: PropertyDescriptor类表示JavaBean类通过存储器导出一个属性。 } 测试类: package com.learn.reflect; import java.beans.IntrospectionException; import java.beans.PropertyDescriptor prop = new PropertyDescriptor(“id”, person.class); // 获取getter方法,反射获取id值 Object str
PropertyDescriptor 类表示 JavaBean 类通过存储器导出一个属性。 构造方法有: PropertyDescriptor(String propertyName, Class<? > beanClass) PropertyDescriptor(String propertyName, Class<? > beanClass, String readMethodName, String writeMethodName) PropertyDescriptor(String propertyName, 用法: import java.beans.PropertyDescriptor; import java.lang.reflect.Field; import java.lang.reflect.Method 实际情况中需要判断下他的参数类型 } //读数据 for (Field f : fields) { PropertyDescriptor pd = new PropertyDescriptor(f.getName
1、PropertyDescriptor简述 PropertyDescriptor对象是位于java.beans包下的工具类,顾名思义为属性描述器,通常我们用于通过反射获取对象方法的时候,下面来看一下常用的用法吧 2、PropertyDescriptor用法 (1)、给你一个java对象,你如何生成PropertyDescriptor对象呢? PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); PropertyDescriptor[] studentDescriptors System.out.println(“studentDescriptors:”+JSON.toJSONString(studentDescriptors)); 这里我们看一下获取到的一个PropertyDescriptor return; } // 获取student1的所有属性及方法 PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); PropertyDescriptor
1.作用域 PropertyDescriptor中文叫属性描述器,是jiava JavaBean的内省与BeanUtils库 JavaBean是一种特殊的类,主要用于传递数据信息,这种类中的方法主要用于访问私有的字段 PropertyDescriptor JDK内省类库: PropertyDescriptor类:(属性描述器) PropertyDescriptor类表示JavaBean类通过存储器导出一个属性。 其他和PropertyDescriptor 相关的类或者工具包 1. Introspector类: 将JavaBean中的属性封装起来进行操作 得到 BeanInfo 2. BeanInfo操作PropertyDescriptor 3. descriptor = new PropertyDescriptor("name",TestClass.class); final Class<?
static String getValueByFiled(String fieldName,Object obj)throws Exception{ //属性扫描器 PropertyDescriptor pd = new PropertyDescriptor(fieldName, obj.getClass()); //从属性描述器中获取 get 方法 Method (value); } 下面是比较完整的 public class PropertyUtil { @SuppressWarnings("unchecked") public static PropertyDescriptor pd = new PropertyDescriptor(f.getName(), clazz); Method wM = pd.getWriteMethod();//获得写方法 wM.invoke 实际情况中需要判断下他的参数类型 } //读数据 for(Field f : fields) { PropertyDescriptor pd = new PropertyDescriptor
JDK内省类库: PropertyDescriptor类:(属性描述器) PropertyDescriptor类表示JavaBean类通过存储器导出一个属性。 propDesc = new PropertyDescriptor(userName, UserInfo.class); // 获得用于写入属性值的方法 Method proDescriptor = new PropertyDescriptor(userName, UserInfo.class); // 获得用于读取属性值的方法 = null && proDescrtptors.length > 0) { for (PropertyDescriptor propDesc : proDescrtptors) { // 找到则写入属性值 ,只是方式不一样:前者通过创建对象直接获得,后者需要遍历,所以使用PropertyDescriptor类更加方便。
> getWrappedClass(); // 获取属性们的PropertyDescriptor 获取属性们 PropertyDescriptor[] getPropertyDescriptors // 是否可读、可写 都是由PropertyDescriptor 去决定了~ // java.beans.PropertyDescriptor~~ public BeanPropertyHandler 而PropertyDescriptor中比较特殊的是因为有getClass()方法,因此class也算是一个PropertyDescriptor,但是它没有writeMethod哦~ 关于BeanInfo { PropertyDescriptor age = new PropertyDescriptor("age", Child.class); System.out.println 它是Spring提供的专门用于缓存JavaBean的PropertyDescriptor描述信息的类,不能被应用代码直接使用。
一、软件包 java.beans 包含与开发 beans 有关的类 二、PropertyDescriptor PropertyDescriptor 描述 Java Bean 通过存储器方法导出的一个属性 构造方法: PropertyDescriptor(String propertyName, Class<? > beanClass) PropertyDescriptor(String propertyName, Class<? > beanClass, String readMethodName, String writeMethodName) PropertyDescriptor(String propertyName, public PropertyDescriptor(String propertyName, Class<?
_property; public PropertyDescriptor property { get { return _property; propertyDescriptor; public SortableBindingList() : base(new List<T>()) SortPropertyCore { get { return this.propertyDescriptor; } } protected propertyDescriptor; private int reverse; public PropertyComparer(PropertyDescriptor (PropertyDescriptor descriptor) { this.propertyDescriptor = descriptor; }
PropertyDescriptor 4. 实例 简介 BeanWrapper是Spring底层经常使用的一个接口,简单来说是对Bean的一种包装,包括对Bean的属性、方法,数据等。 getPropertyDescriptor(String propertyName:获取指定属性的PropertyDescriptor public PropertyDescriptor[] getPropertyDescriptors ():获取所有属性的PropertyDescriptor【包括继承而来的】 public Object getPropertyValue(String propertyName):获取指定属性的值 PropertyDescriptor 两个概念如下: ReadMethod:即是对应属性的get方法 WriteMethod:即是对应属性的set方法 实例 我们可以同BeanWrapper和PropertyDescriptor可以很轻松实现属性的复制 (); //根据名称分组,减少一层循环 Map<String, List<PropertyDescriptor>> map = Arrays.asList(sourcePds