依赖
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
public class BeanGeneratorTestMain {
public static void main(String[] args) {
BeanGenerator generator = new BeanGenerator();
generator.addProperty("xxxId", Long.class);
generator.addProperty("xxxName", String.class);
generator.addProperty("xxxDescription", String.class);
Object obj = generator.create();
BeanMap beanMap = BeanMap.create(obj);
beanMap.put("xxxId", 2L);
beanMap.put("xxxName", "这是XXName");
beanMap.put("xxxDescription", "这是一个描述");
System.out.println(JSON.toJSONString(obj));
System.out.println("-----------------");
}
}
输出
{"xxxDescription":"这是一个描述","xxxId":2,"xxxName":"这是XXName"}
-----------------
网友评论