net.sf.cglib.beans.BeanGenerator

2021-01-21  本文已影响0人  东南枝下

依赖

<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"}
-----------------
上一篇下一篇

猜你喜欢

热点阅读