当前位置:网站首页>实体中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
边栏推荐
- Frequently asked interview questions - 1 (non technical)
- QT displays the specified position and size of the picture
- (11) Vscode code formatting configuration
- Pavlov and hobbies
- Deep learning object detection
- Relative reference and absolute reference of Excel
- QSS, qdateedit, qcalendarwidget custom settings
- Strategies to improve Facebook's touch rate and interaction rate | intelligent customer service helps you grasp users' hearts
- Shell instruction learning 1
- Redis经典面试题总结2022
猜你喜欢
The 8th Blue Bridge Cup 2017 - frog jumping cup
C, class library
C language - Spoof shutdown applet
Create process memory management copy_ Mm - processes and threads (IX)
(11) Vscode code formatting configuration
Issue 36 summary of atcoder beginer contest 248
[no title] Click the classification jump page to display the details
Flutter nouvelle génération de rendu graphique Impeller
QT drawpixmap and DrawImage blur problem
deep learning object detection
随机推荐
Breadth first search topics (BFS)
提升独立站转化率攻略 | 挽回弃购用户
Fletter next generation graphics renderer impaller
Map对象 map.get(key)
C language - Spoof shutdown applet
QSslSocket::connectToHostEncrypted: TLS initialization failed
Range of numbers (dichotomous classic template topic)
Several examples of pointer transfer, parameter transfer, value transfer, etc
Write the declaration of a function to return the reference of the array, and the array contains 10 string objects (notes)
Hongji micro classroom | cyclone RPA's "flexible digital employee" actuator
Simple and basic use of switch and if
open3d材质设置参数分析
Double click The jar package cannot run the solution
qt. qpa. plugin: Could not find the Qt platform plugin “xcb“ in ““
Golang通过exec模块实现Ping连通性检测案例
mysql中duplicate key update
3d slicer中拉直体的生成
uni使用的一些坑
SQL语句简单优化
Generation of straightening body in 3D slicer