|
@@ -4,23 +4,37 @@ import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.LocalTime;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.function.Supplier;
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
public class DataUtil {
|
|
public class DataUtil {
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(DataUtil.class);
|
|
private static final Logger log = LoggerFactory.getLogger(DataUtil.class);
|
|
- static Map<Class<?>, Supplier<?>> defaultValues = Map.of(
|
|
|
|
|
|
+ static Map<Class<?>, Supplier<?>> dateValues = Map.of(
|
|
|
|
+ java.sql.Date.class, () -> new java.sql.Date(System.currentTimeMillis()),
|
|
|
|
+ java.util.Date.class, () -> new java.util.Date(System.currentTimeMillis()),
|
|
|
|
+ LocalDate.class, LocalDate::now,
|
|
|
|
+ LocalDateTime.class, LocalDateTime::now,
|
|
|
|
+ LocalTime.class, LocalTime::now
|
|
|
|
+ );
|
|
|
|
+ static Map<Class<?>, Supplier<?>> simpleValues = Map.of(
|
|
String.class, () -> "",
|
|
String.class, () -> "",
|
|
Integer.class, () -> 0,
|
|
Integer.class, () -> 0,
|
|
Double.class, () -> 0.0,
|
|
Double.class, () -> 0.0,
|
|
Float.class, () -> 0.0F,
|
|
Float.class, () -> 0.0F,
|
|
Boolean.class, () -> false,
|
|
Boolean.class, () -> false,
|
|
- java.sql.Date.class, () -> new java.sql.Date(System.currentTimeMillis()),
|
|
|
|
- java.util.Date.class, () -> new java.util.Date(System.currentTimeMillis()),
|
|
|
|
Long.class, () -> 0L,
|
|
Long.class, () -> 0L,
|
|
BigDecimal.class, () -> BigDecimal.ZERO
|
|
BigDecimal.class, () -> BigDecimal.ZERO
|
|
);
|
|
);
|
|
|
|
+ static Map<Class<?>, Supplier<?>> defaultValues = new HashMap<>(simpleValues);
|
|
|
|
+
|
|
|
|
+ static {
|
|
|
|
+ defaultValues.putAll(dateValues);
|
|
|
|
+ }
|
|
|
|
|
|
public static <T> Object getDataDefault(Object object, Class<T> clazz) {
|
|
public static <T> Object getDataDefault(Object object, Class<T> clazz) {
|
|
if (object == null) {
|
|
if (object == null) {
|