BeanGenerator and how to use it
Chúng ta có thể dễ dàng tạo ra một class POJO hay một Bean bằng cách lập trình động, động ở việc thêm thuộc tính cho nó, kiểu dữ liệu các thuộc tính, động ở việc set giá trị thuộc tính bằng cách gọi đúng tên theo quy ước lạc đà
BeanGenerator beanGenerator = new BeanGenerator(); beanGenerator.addProperty("name", List.class); Object myBean = beanGenerator.create(); Method setter = myBean.getClass().getMethod("setName", List.class); List<String> list= new ArrayList<String>(); list.add("Bộ"); setter.invoke(myBean, list); Method getter = myBean.getClass().getMethod("getName"); System.out.println(getter.getDeclaringClass());
Comments
Post a Comment