mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-05 20:33:23 +08:00
增加时间转换
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user