|
这个主题共有 1 回复 / 1 页 [
]
|
|
|
|
|
|
Banq,请教如何动态实现标准java bean?
|
发表: 2005年07月28日 15:37
|
回复
|
|
用common属性包可实现如下动态bean,但是假的bean: DynaProperty[] px = { new DynaProperty("firstName", Class.forName("java.lang.String")), new DynaProperty("lastName", Class.forName("java.lang.String")) }; DynaClass dynaClass = new BasicDynaClass("employee", null, px);
DynaBean employee = dynaClass.newInstance(); PropertyUtils.setProperty(employee, "firstName", "Fred"); PropertyUtils.setProperty(employee, "lastName", "Flintstone");
System.out.println("firstName:" + PropertyUtils.getProperty(employee, "firstName")); System.out.println("lastName:" + PropertyUtils.getProperty(employee, "lastName"));
由于特殊需要,须按如下反射方式取得bean属性,但系统抛出NoSuchMethodException:
Method method = employee.getClass().getMethod("getLastName", null); debug(method.invoke(employee, null));
可否告知有无方法实现一个标准规范的bean,即可按反射方式取得属性。 先多谢了。
|
|
|
|
|
|
Re: Banq,请教如何动态实现标准java bean?
|
发表: 2005年07月29日 11:10
|
回复
|
|
|
不是很清楚,标准javabean应该是能编译通过就可以吧?
|
|
|
|