chengf
2025-07-04 a26c074129afced8fe87e300fb501030fde0c056
java110-utils/src/main/java/com/java110/utils/util/Java110Converter.java
old mode 100644 new mode 100755
@@ -6,6 +6,9 @@
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
/**
@@ -17,7 +20,7 @@
 * add by wuxw 2020/1/28
 **/
public class Java110Converter implements Converter {
    static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Override
    public Object convert(Object value, Class target, Object context) {
@@ -26,6 +29,8 @@
    }
    public static Object getValue(Object value, Class target) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (value == null) {
            return value;
@@ -53,6 +58,15 @@
            return value;
        }
        //2.0 Date 转 Date
        if (value instanceof LocalDateTime && target == Date.class) {
            ZoneId zoneId = ZoneId.systemDefault();
            ZonedDateTime zonedDateTime = ((LocalDateTime)value).atZone(zoneId);
            Date date = Date.from(zonedDateTime.toInstant());
            return date;
        }
        // 3.0 Date 转 String
        if (value instanceof Date && target == String.class) {
            Date date = (Date) value;
@@ -76,7 +90,7 @@
            return newDate;
        }
        if (value instanceof BigDecimal) {
        if (value instanceof BigDecimal && target == String.class) {
            BigDecimal bd = (BigDecimal) value;
            return bd.toPlainString();
        }
@@ -85,14 +99,23 @@
        }
        if (target == int.class || target == Integer.class) {
            if(StringUtil.isNullOrNone(value)){
                return 0;
            }
            return Integer.parseInt(String.valueOf(value));
        }
        if (target == long.class || target == Long.class) {
            if(StringUtil.isNullOrNone(value)){
                return 0;
            }
            return Long.parseLong(String.valueOf(value));
        }
        if (target == double.class || target == Double.class) {
            if(StringUtil.isNullOrNone(value)){
                return 0;
            }
            return Double.parseDouble(String.valueOf(value));
        }
@@ -100,6 +123,15 @@
            return String.valueOf(value).split(",");
        }
        //1.0 String 转 Date
        if (value instanceof String && target == boolean.class) {
            String bl = (String) value;
            if ("true".equals(bl)) {
                return true;
            }
            return false;
        }
        return value;
    }
}