集册 Java实例教程 获取bean类的bean信息。

获取bean类的bean信息。

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

427
获取bean类的bean信息。


import java.beans.BeanInfo;//时代Java 提供

import java.beans.IntrospectionException;

import java.beans.Introspector;

import java.beans.PropertyDescriptor;

import java.lang.reflect.Field;

import java.lang.reflect.InvocationTargetException;

import java.lang.reflect.Method;

import java.text.MessageFormat;


public class Main{

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

        Object bean = "nowjava.com";

        System.out.println(getBeanInfo(bean));

    }

    /**

     * Obtain the bean info for a bean class.

     * 

     * @param beanClass

     *            A java bean <code>Class</code>.

     * @return A <code>BeanInfo</code>.

     */

    private static BeanInfo getBeanInfo(final Object bean) {

        try {

            return Introspector.getBeanInfo(bean.getClass());

     
展开阅读全文