old mode 100644
new mode 100755
| | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | public static Object getValue(Object value, Class target) { |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | if (value == null) { |
| | | return value; |
| | | } |
| | |
| | | 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; |
| | |
| | | return newDate; |
| | | } |
| | | |
| | | if (value instanceof BigDecimal) { |
| | | if (value instanceof BigDecimal && target == String.class) { |
| | | BigDecimal bd = (BigDecimal) value; |
| | | return bd.toPlainString(); |
| | | } |
| | |
| | | } |
| | | |
| | | 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)); |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | | } |