当前位置:网站首页>实体中list属性为空或者null,设置为空数组
实体中list属性为空或者null,设置为空数组
2022-04-23 05:38:00 【wyazyf】
/**
* //处理空数组
* @param object
* @throws Exception
*/
public static void getObjectValue(Object object) throws Exception {
if (object != null) {//if (object!=null ) ----begin
// 拿到该类
Class<?> clz = object.getClass();
// 获取实体类的所有属性,返回Field数组
Field[] fields = clz.getDeclaredFields();
for (Field field : fields) {// --for() begin
if(field.getGenericType().toString().contains("java.util.List")){
if(field.get(object)==null){
field.setAccessible(true);
field.set(object,new ArrayList<>());
// System.out.println("属性名:" + field.getName());
// System.out.println("属性类型:" + field.getGenericType());
// System.out.println("属性值:" + String.valueOf(field.get(object)));
}
}
}
}
}
版权声明
本文为[wyazyf]所创,转载请带上原文链接,感谢
https://blog.csdn.net/wyazyf/article/details/113233967
边栏推荐
- Map对象 map.get(key)
- Edit, cancel, pull up menu
- Rog attack
- Error 2003 (HY000) when Windows connects MySQL: can't connect to MySQL server on 'localhost' (10061)
- 转置卷积(Transposed Convolution)
- ‘EddiesObservations‘ object has no attribute ‘filled‘
- Excel 2016 cannot open the file for the first time. Sometimes it is blank and sometimes it is very slow. You have to open it for the second time
- 提升独立站转化率攻略 | 挽回弃购用户
- Various situations of data / component binding
- OSI层常用协议
猜你喜欢

Excel sets row and column colors according to cell contents

Parameter analysis of open3d material setting

C language - Spoof shutdown applet

Differences between sea level anatomy and sea surface height anatomy

Create cells through JS (while loop)

Batch import of orange single micro service

Box collapse and margin collapse

QT displays the specified position and size of the picture

引航成长·匠心赋能——YonMaster开发者培训领航计划全面开启

Pol / select / EPO
随机推荐
橙单微服务之批量导入
Issue 36 summary of atcoder beginer contest 248
修仙真实世界与游戏世界
[no title] Click the classification jump page to display the details
巴普洛夫与兴趣爱好
Traversal array, object parent-child communication props / $emit
Linear sieve method (prime sieve)
Batch import of orange single micro service
Typescript interface & type rough understanding
Intel SGX preliminary learning and understanding notes (continuously updated)
Three methods of list rendering
X86 assembly syntax: at & T and Intel
Quick app bottom navigation bar
Cmake basic tutorial (39) pkgconfig
Frequently asked interview questions - 2 (computer network)
Radar equipment (greedy)
STL function library
(11) Vscode code formatting configuration
Add two pointers? (legal or illegal)
xxl-job采坑指南xxl-rpc remoting error(connect timed out)