集册 Java实例教程 获取Java Bean读取方法

获取Java Bean读取方法

欢马劈雪     最近更新时间:2020-01-02 10:19:05

512
获取Java Bean读取方法

/**

 * Archivists' Toolkit(TM) Copyright ? 2005-2007 Regents of the University of California, New York University, & Five Colleges, Inc.

 * All rights reserved.

 *

 * This software is free. You can redistribute it and / or modify it under the terms of the Educational Community License (ECL)

 * version 1.0 (http://www.opensource.org/licenses/ecl1.php)

 *

 * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty

 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ECL license for more details about permissions and limitations.

 *

 *

 * Archivists' Toolkit(TM)

 * http://www.archiviststoolkit.org

 * info@archiviststoolkit.org

 *

 * @author Lee Mandell

 * Date: Mar 18, 2006

 * Time: 5:34:03 PM

 *//*n o w j a   v  a . c o m - 时  代  Java 提 供*/

//package com.nowjava;

import java.beans.BeanInfo;

import java.beans.Introspector;

import java.beans.PropertyDescriptor;

import java.beans.IntrospectionException;

import java.lang.reflect.Method;


public class Main {

    public static void main(String[] argv) throws Exception {

        Class clazz = String.class;

        String propertyName = "nowjava.com";

        System.out.println(getReadMethod(clazz, propertyName));

    }


    public static Method getReadMethod(Class clazz, String propertyName)

            throws IntrospectionException {

        BeanInfo beanInfo = Introspector.getBeanInfo(clazz);/** 时 代 J a v a 公 众 号 - N o w J a v  a . c o m 提 供 **/

        PropertyDescriptor[] propertyDescriptors = be
展开阅读全文