| | |
| | | } |
| | | |
| | | public static Object getValue(Object value, Class target) { |
| | | |
| | | if (value == null) { |
| | | return value; |
| | | } |
| | | //1.0 String 转 Date |
| | | if (value instanceof String && target == Date.class) { |
| | | String date = (String) value; |
| | | Date newDate = null; |
| | | SimpleDateFormat strdf = null; |
| | | if (date.contains(":")) { |
| | | //sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); |
| | | strdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); |
| | | } else { |
| | | sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | strdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | } |
| | | try { |
| | | newDate = sdf.parse(date); |
| | | newDate = strdf.parse(date); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | // 3.0 Date 转 String |
| | | if (value instanceof Date && target == String.class) { |
| | | Date date = (Date) value; |
| | | String newDate = null; |
| | | try { |
| | | newDate = sdf.format(date); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return newDate; |
| | | } |
| | | // 3.0 Timestamp 转 String |
| | | if (value instanceof Timestamp && target == String.class) { |
| | | Date date = new Date(((Timestamp) value).getTime()); |
| | | String newDate = null; |
| | | try { |
| | | newDate = sdf.format(date); |
| | |
| | | return Double.parseDouble(String.valueOf(value)); |
| | | } |
| | | |
| | | if (target == String[].class) { |
| | | return String.valueOf(value).split(","); |
| | | } |
| | | |
| | | return value; |
| | | } |
| | | } |