增加时间转换

This commit is contained in:
zhouhao
2018-04-16 16:20:37 +08:00
parent 54f13cd53e
commit fbb01b7a7d
3 changed files with 29 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.PropertyUtilsBean;
import org.hswebframework.utils.time.DateFormatter;
import org.hswebframework.web.dict.EnumDict;
import org.hswebframework.web.proxy.Proxy;
import org.springframework.util.ClassUtils;
@@ -400,11 +401,26 @@ public final class FastBeanCopier {
}
}
if (targetClass == String.class) {
if (source instanceof Date) {
// TODO: 18-4-16 自定义格式
return (T) DateFormatter.toString(((Date) source), "yyyy-MM-dd HH:mm:ss");
}
return (T) String.valueOf(source);
}
if (targetClass == Object.class) {
return (T) source;
}
if (targetClass == Date.class) {
if (source instanceof String) {
return (T) DateFormatter.fromString((String) source);
}
if (source instanceof Number) {
return (T) new Date(((Number) source).longValue());
}
if (source instanceof Date) {
return (T) new Date(((Date) source).getTime());
}
}
org.apache.commons.beanutils.Converter converter = BeanUtilsBean
.getInstance()
.getConvertUtils()

View File

@@ -22,6 +22,12 @@ public class Source {
private int age3;
private Date deleteTime=new Date();
private Date createTime=new Date();
private String updateTime="2018-01-01";
private NestObject nestObject;

View File

@@ -3,6 +3,7 @@ package org.hswebframework.web.bean;
import lombok.Data;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -23,6 +24,12 @@ public class Target {
private String age3;
private Date deleteTime=new Date();
private String createTime;
private Date updateTime;
private NestObject nestObject;
private NestObject nestObject2;