全局处理返回日期格式

20230922-ljl-fixBug
wangchaoxu 1 year ago
parent 1636aefef2
commit 7df2de4dae

@ -30,7 +30,6 @@ public class DsAutoPurchaseSwitchLogDTO {
/** /**
* *
*/ */
@JSONField(format="yyyy-MM-dd HH:mm:ss")
private Date gmtCreate; private Date gmtCreate;
} }

@ -1,13 +1,12 @@
package com.ms.api.common; package com.ms.api.common;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.Data; import lombok.Data;
import java.util.Map;
/** /**
* *
*/ */
@ -48,12 +47,14 @@ public class Ret {
if (ObjectUtil.isEmpty(data)){ if (ObjectUtil.isEmpty(data)){
return new Ret("success", data); return new Ret("success", data);
} }
for (Object key : data.keySet()) { // for (Object key : data.keySet()) {
if (data.get(key) instanceof Date){ // if (data.get(key) instanceof Date){
data.put(key,DateUtil.formatDateTime((Date) data.get(key))); // data.put(key,DateUtil.formatDateTime((Date) data.get(key)));
} // }
} // }
return new Ret("success", data); // return new Ret("success", data);
String jsonStr = JSONObject.toJSONString(data, SerializerFeature.WriteDateUseDateFormat);
return new Ret("success", JSONObject.parseObject(jsonStr));
} }
public static Ret fail() { public static Ret fail() {

Loading…
Cancel
Save