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

Popular posts from this blog

Fixing the DeepSpeed Import Error While Fine-Tuning the Qwen Model

Amazon Linux 2023 - User data configuration for launch templates to connect to the EKS cluster

How to create ISM policy and rotate logs in opensearch