| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 通过反射对象填充 |
| | | * 刘苏义 |
| | | * 2024/4/2 11:50:57 |
| | | */ |
| | | public static void fillNullFields(Object source, Object target) { |
| | | if (source == null || target == null) { |
| | | return; |
| | | } |
| | | Field[] fields = source.getClass().getDeclaredFields(); |
| | | for (Field field : fields) { |
| | | field.setAccessible(true); |
| | | try { |
| | | Object sourceValue = field.get(source); |
| | | Object targetValue = field.get(target); |
| | | if (targetValue == null && sourceValue != null) { |
| | | field.set(target, sourceValue); |
| | | } |
| | | } catch (IllegalAccessException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |