当前位置:网站首页>The object needs to add additional attributes. There is no need to add attributes in the entity. The required information is returned
The object needs to add additional attributes. There is no need to add attributes in the entity. The required information is returned
2022-04-23 04:43:00 【Mount MONI】
User object , Yes id and name Two attributes
Now I want to add additional address and age The value of the property
// Object needs additional attributes , There is no need to add attributes to the entity , Return the required information
User user = new User();
String[] colStrings = {"a", "b", "c"};
user = CommonUtils.generateBean(user, colStrings);
BeanMap create = BeanMap.create(user);
create.put("address", "aaaaaaa");
create.put("age", "11");
user = (User) create.getBean();
System.out.println(CommonUtils.toJSONStringContainNullValue(user));
/**
* Dynamically add attribute values
* @param t Entity
* @param columns Attribute array
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T generateBean(T t,String... columns){
BeanGenerator generator = new BeanGenerator();
generator.setSuperclass(t.getClass());
for(String str : columns){
generator.addProperty(str, Object.class);
}
Object o=generator.create();
BeanUtils.copyProperties(t, o);
return (T)o;
}
版权声明
本文为[Mount MONI]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220558291727.html
边栏推荐
- 程序员抱怨:1万2的工资我真的活不下去了,网友:我3千咋说
- /etc/bash_ completion. D directory function (the user logs in and executes the script under the directory immediately)
- 2019 is coming to an end, the longest day.
- Spark FAQ sorting - must see before interview
- The last day of 2021 is the year of harvest.
- Go反射法则
- 三十六计是什么
- leetcode003--判断一个整数是否为回文数
- KVM error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock‘
- 华为机试--高精度整数加法
猜你喜欢
Unity rawimage background seamlessly connected mobile
Microbial neuroimmune axis -- the hope of prevention and treatment of cardiovascular diseases
520. Detect capital letters
QML进阶(四)-绘制自定义控件
Use recyclerview to realize left-right side-by-side classification selection
補:注解(Annotation)
Record the ThreadPoolExecutor main thread waiting for sub threads
Recommended scheme for national production of electronic components of wireless keyboard
Small volume Schottky diode compatible with nsr20f30nxt5g
Bridge between ischemic stroke and intestinal flora: short chain fatty acids
随机推荐
Supplément: annotation
Shanghai Hangxin technology sharing 𞓜 overview of safety characteristics of acm32 MCU
Interaction of diet gut microbiota on cardiovascular disease
Gut liver axis: host microbiota interaction affects hepatocarcinogenesis
Redis command Encyclopedia
Fusobacterium -- symbiotic bacteria, opportunistic bacteria, oncobacterium
520. Detect capital letters
Spark small case - RDD, spark SQL
Leetcode005 -- delete duplicate elements in the array in place
The 14th issue of HMS core discovery reviews the long article | enjoy the silky clip and release the creativity of the video
Key points of AWS eks deployment and differences between console and eksctl creation
Flink case - Kafka, MySQL source
zynq平台交叉编译器的安装
补充番外14:cmake实践项目笔记(未完待续4/22)
The perfect combination of collaborative process and multi process
Recursive call -- Enumeration of permutations
1个需求的一生,团队协作在云效钉钉小程序上可以这么玩
Case of using stream load to write data to Doris
2020 is coming to an end, special and unforgettable.
Go reflection rule