DynaBean DynaClass DynaProperty
DynaBean实现DynaClass来处理属性
DynaProperty(name,type,contentType)
如果实现List,Map ,contentType代表元素类别(判断type为primitive,写true,primitive编号
//dynaBeanClass为任意的实现了DynaBean接口的类,constructorTypes为这个
//类的构造方法所需要的参数的类型
constructor = dynaBeanClass.getConstructor(constructorTypes);
//constructorValues为构造方法的参数值,实际上它的值为当前的BasicDynaClass
return ((DynaBean) constructor.newInstance(constructorValues));
①BasicDynaClass() 自己通过set器初始化;
②BasicDynaClass(String name, Class dynaBeanClass) 如果你传递的不是LazyDynaBean
③BasicDynaClass(String name, Class dynaBeanClass, DynaProperty[] properties)建议使用这个,
DynaProperty[] props = new DynaProperty[] {//属性
new DynaProperty("name", String.class),
new DynaProperty("age", Integer.class),
new DynaProperty("birth", Date.class) };
BasicDynaClass testClass = new BasicDynaClass("politician", //class
BasicDynaBean.class, props);
DynaBean dynaBean = testClass.newInstance(); //实例
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
dynaBean.set("name", "测试用户");
dynaBean.set("age", 22);
dynaBean.set("birth", sdf.parse("1988-10-17"));
StringBuilder sb = new StringBuilder();
sb.append("name:").append(dynaBean.get("name")).append("\nage").append(
dynaBean.get("age")).append("\nbirth:").append(
dynaBean.get("birth"));
System.out.println(sb.toString());