当前位置:网站首页>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
边栏推荐
- Flink's important basics
- 补:注解(Annotation)
- Redis command Encyclopedia
- Last day of 2017
- KVM error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock‘
- Ali's ten-year technical experts jointly created the "latest" jetpack compose project combat drill (with demo)
- The perfect combination of collaborative process and multi process
- Phishing for NFT
- Spark FAQ sorting - must see before interview
- leetcode002--将有符号整数的数字部分反转
猜你喜欢

zynq平台交叉编译器的安装

Shanghai Hangxin technology sharing 𞓜 overview of safety characteristics of acm32 MCU

Jetpack 之 LifeCycle 组件使用详解

用D435i录制自己的数据集运行ORBslam2并构建稠密点云

程序员抱怨:1万2的工资我真的活不下去了,网友:我3千咋说

New terminal play method: script guidance independent of technology stack

Microbial neuroimmune axis -- the hope of prevention and treatment of cardiovascular diseases

Recommended scheme for national production of electronic components of wireless keyboard

Youqilin 22.04 lts version officially released | ukui 3.1 opens a new experience

基于英飞凌MCU GTM模块的无刷电机驱动方案开源啦
随机推荐
Record the ThreadPoolExecutor main thread waiting for sub threads
Go反射—Go语言圣经学习笔记
2019 is coming to an end, the longest day.
The perfect combination of collaborative process and multi process
那些年我面试过的Android开发岗总结(附面试题+答案解析)
PIP3 installation requests Library - the most complete pit sorting
Leetcode004 -- Roman numeral to integer
Special topic of data intensive application system design
Interaction of diet gut microbiota on cardiovascular disease
Flink case - Kafka, MySQL source
229. 求众数 II
Unity camera rotation with sliding effect (rotation)
程序员抱怨:1万2的工资我真的活不下去了,网友:我3千咋说
Experience summary and sharing of the first prize of 2021 National Mathematical Modeling Competition
Detailed explanation of life cycle component of jetpack
Luogu p1858 [multi person knapsack] (knapsack seeking the top k optimal solution)
Go反射法则
What is a blocking queue? What is the implementation principle of blocking queue? How to use blocking queue to implement producer consumer model?
Alibaba tip: it is better to create threads manually
Innovative practice of short video content understanding and generation technology in meituan