美文网首页
net.sf.cglib.beans.BeanGenerator

net.sf.cglib.beans.BeanGenerator

作者: 东南枝下 | 来源:发表于2021-01-21 21:15 被阅读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"}
    -----------------
    

    相关文章

      网友评论

          本文标题:net.sf.cglib.beans.BeanGenerator

          本文链接:https://www.haomeiwen.com/subject/cltjzktx.html