当前位置:网站首页>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
边栏推荐
- Practice and exploration of knowledge map visualization technology in meituan
- /etc/bash_ completion. D directory function (the user logs in and executes the script under the directory immediately)
- Luogu p1858 [multi person knapsack] (knapsack seeking the top k optimal solution)
- Leetcode009 -- search the target value in the array with binary search
- Mysql50 basic exercises
- Use recyclerview to realize left-right side-by-side classification selection
- 做数据可视化应该避免的8个误区
- What is the thirty-six plan
- win10, mysql-8.0.26-winx64. Zip installation
- Eight misunderstandings that should be avoided in data visualization
猜你喜欢
383. Ransom letter
win10, mysql-8.0.26-winx64.zip 安装
RC低通滤波器的逆系统
Phishing for NFT
Detailed explanation of life cycle component of jetpack
Experience summary and sharing of the first prize of 2021 National Mathematical Modeling Competition
Inverse system of RC low pass filter
Programmers complain: I really can't live with a salary of 12000. Netizen: how can I say 3000
Key points of AWS eks deployment and differences between console and eksctl creation
Use recyclerview to realize left-right side-by-side classification selection
随机推荐
重剑无锋,大巧不工
Bridge between ischemic stroke and intestinal flora: short chain fatty acids
Unity3D 实用技巧 - 理论知识库(一)
The perfect combination of collaborative process and multi process
Coinbase: basic knowledge, facts and statistics about cross chain bridge
Last day of 2017
C language: spoof games
Installation and deployment of Flink and wordcount test
What is a blocking queue? What is the implementation principle of blocking queue? How to use blocking queue to implement producer consumer model?
那些年我面试过的Android开发岗总结(附面试题+答案解析)
QML进阶(五)-通过粒子模拟系统实现各种炫酷的特效
What is the meaning of load balancing
简单的拖拽物体到物品栏
Go反射—Go语言圣经学习笔记
JS generates a specified number of characters according to some words
C language: Advanced pointer
Leetcode002 -- inverts the numeric portion of a signed integer
针对NFT的网络钓鱼
Shanghai Hangxin technology sharing 𞓜 overview of safety characteristics of acm32 MCU
[pytoch foundation] torch Split() usage