public static <T> T setValue(@NotNull T data) {
Class<?> aClass = data.getClass();
try {
Field declaredField = aClass.getDeclaredField("createTime");
declaredField.setAccessible(true);
declaredField.set(data, LocalDateTime.now());
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
return data;
}
public static <T> T setValue(@NotNull T data,@NotNull String...fieldNames) {
Class<?> aClass = data.getClass();
if (fieldNames.length == 0) {
return data;
}
for (String fieldName : fieldNames) {
try {
Field declaredField = aClass.getDeclaredField(fieldName);
declaredField.setAccessible(true);
declaredField.set(data, LocalDateTime.now());
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return data;
}