| | |
| | | |
| | | try { |
| | | File file = new File(fileName); |
| | | File parentDir = file.getParentFile(); |
| | | if (!parentDir.exists()) { |
| | | parentDir.mkdirs(); // 创建文件所在的目录,包括父目录 |
| | | } |
| | | boolean fileExists = file.exists(); |
| | | boolean dataExists = false; |
| | | if(fileExists) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 通过反射对象填充 |
| | | * 刘苏义 |
| | | * 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(); |
| | | } |
| | | } |
| | | } |
| | | } |