org.springframework.cglib.beans.BeanMap的使用

org.springframework.cglib.beans.BeanMap可以快捷、优雅的将Java entity bean 转换为Map对象;但是使用时也需要主要,org.springframework.cglib.beans.BeanMap直接转换出来的Map对象,做不了put操作;例如:

LoggerIndex index = new LoggerIndex();
index.setLoggerTableName("teset1");
index.setLoggerIndexId(UUID.randomUUID().toString());
index.setLoggerTableName("tablename");
index.setLoggerBusSysCode("am");

Map map = BeanMap.create(index);

map.put("test1", "test1");

System.out.println(map.toString());

map.put("test1", "test1");并没有生效,打印出来的数据没有test1的数据;打印的接口如下:

{loggerSubTableTime=null, loggerSubTableName=null, loggerSubTableType=null, loggerBusSysCode=am, loggerTableName=tablename, loggerIndexId=dbc7d710-3a95-43c4-8013-0bed26be27a3}

 

再看下面的处理:

LoggerIndex index = new LoggerIndex();
index.setLoggerTableName("teset1");
index.setLoggerIndexId(UUID.randomUUID().toString());
index.setLoggerTableName("tablename");
index.setLoggerBusSysCode("am");

Map map = BeanMap.create(index);

Map resMap = new HashMap();
resMap.putAll(map);

resMap.put("test1", "test1");

System.out.println(resMap.toString());

重新定义一个HashMap将转换出来的map,putAll进去定义的HashMap(resMap );对resMap 进行put操作;打印结果如下:

{loggerSubTableTime=null, loggerSubTableName=null, loggerSubTableType=null, loggerBusSysCode=am, loggerTableName=tablename, loggerIndexId=25a46e5a-a349-4e98-9e09-46851d3f1219, test1=test1}

 

此时test1的数据正常打印出来。

 

 

你可能感兴趣的:(java,java,spring-boot,BeanMap)