不太明白什么意思,但是如果有个BEAN,就想知道里面的属性和方法的话,我想可以有很多办法:
1。导入到一个IDE工具中直接看
2。用javadoc 去生成一个文档
3。写一个类去返回该BEAN的属性,这个就是昨天的贴子里面有个介绍
4。用对JAVABEAN操作的工具

解决方案 »

  1.   

    fogs(菜鸟想飞) 你严重误解我的意思 treeroot(旗鲁特) 有没有代码 让我参考
      

  2.   

    使用反射beanName.get("properties"),beanName.set("properties")
      

  3.   

    public void test1(){
            try {
                Class cl = Class.forName("test.myjavaBean");
                Object o = cl.newInstance();
                Method[] mts = cl.getMethods();            String strTemp = "";
                int namePos = 0;
                for (int i = 0; i < mts.length; i++) {
                    strTemp = mts[i].getName();
                    if ( (namePos = strTemp.indexOf("set")) >= 0
                        || (namePos = strTemp.indexOf("Set")) >= 0
                        || (namePos = strTemp.indexOf("SET")) >= 0) {
                        System.out.println(mts[i].getReturnType().getName());
                        if (mts[i].getReturnType().getName().equals(
                            "java.lang.String"))
                            o = this.fillObject("好的给你赋了", "java.lang.String",
                                                "set" +
                                                strTemp.substring(3, strTemp.length()),
                                                o);
                        if (mts[i].getReturnType().getName().equals("int"))
                            o = this.fillObject(new Integer(12345),
                                                "java.lang.Integer",
                                                "set" +
                                                strTemp.substring(3, strTemp.length()),
                                                o);                }
                }           

    //bean属性列表
                Field[] fs = cl.getFields();
                for (int j = 0; j < fs.length; j++) {
                    System.out.println("属性类型:"+fs[j].getType());
    System.out.println("属性名称:" + fs[j].getName());
                }        }
            catch (Exception e) {
                e.printStackTrace();
            }    } public Object fillObject(Object value, String type, String method, Object o) {
    try {
    String newm = "g" + method.substring(1);
    //System.out.println("type: " + type + "  " + newm);
    //System.out.println("type: " + type + "  " + method);
    if (type.equals("java.lang.Boolean")) {
    (o.getClass().getMethod(method, new Class[] {boolean.class})).
    invoke(o, new Object[] {value});
    }
    else if (type.equals("java.lang.Double")) {
    (o.getClass().getMethod(method, new Class[] {double.class})).
    invoke(o, new Object[] {value});
    }
    else if (type.equals("java.lang.Float")) {
    (o.getClass().getMethod(method, new Class[] {float.class})).
    invoke(o, new Object[] {value});
    }
    else if (type.equals("java.lang.Integer")) {
    System.out.println("整形赋值" + value);
    (o.getClass().getMethod(method, new Class[] {int.class})).
    invoke(o, new Object[] {value});
    }
    else if (type.equals("java.lang.Long")) {
    (o.getClass().getMethod(method, new Class[] {long.class})).
    invoke(o, new Object[] {value});
    }
    else if (type.equals("java.lang.String")) {
    (o.getClass().getMethod(method, new Class[] {String.class})).
    invoke(o, new Object[] {value});
    }
    else if (type.equals("java.math.BigDecimal")) {
    (o.getClass().getMethod(method, new Class[] {BigDecimal.class})).
    invoke(o, new Object[] {value});
    }
    else if (type.equals("java.sql.Date")) {
    (o.getClass().getMethod(method, new Class[] {Date.class})).
    invoke(o, new Object[] {value});
    }
    else if (type.equals("java.sql.Time")) {
    (o.getClass().getMethod(method, new Class[] {Time.class})).
    invoke(o, new Object[] {value});
    }
    else if (type.equals("java.sql.Timestamp")) {
    (o.getClass().getMethod(method, new Class[] {Timestamp.class})).
    invoke(o, new Object[] {value});
    }
    }
    catch (IllegalAccessException e) {
    e.printStackTrace();
    }
    catch (InvocationTargetException e) {
    e.printStackTrace();
    }
    catch (NoSuchMethodException e) {
    e.printStackTrace();
    } return o;
    }