提交 7f869f11 编写于 作者: U u014427391

fix bug,获取timestamp类型为一串unix long数据,使用fastjson的@JSONField可以解决

上级 e7d51c5a
package com.muses.taoshop.common.core.database.utils;
package com.muses.taoshop.common.core.utils;
import java.text.DateFormat;
import java.text.ParseException;
......
package com.muses.taoshop.common.core.utils;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class JsonDateSerializer extends JsonSerializer<Date> {
private SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override
public void serialize(Date date, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonProcessingException {
String value = dateFormat.format(date);
gen.writeString(value);
}
}
\ No newline at end of file
package com.muses.taoshop.item.entity;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.muses.taoshop.common.core.utils.JsonDateSerializer;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
......@@ -37,15 +40,19 @@ public class ItemCategory {
/**
* 上次修改时间
*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
// @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JSONField(format ="yyyy-MM-dd HH:mm:ss")
// @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
// @JsonSerialize(using=JsonDateSerializer.class)
private Date lastModifyTime;
/**
* 创建时间
*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss" )
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
// @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss" )
@JSONField(format ="yyyy-MM-dd HH:mm:ss")
// @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
// @JsonSerialize(using=JsonDateSerializer.class)
private Date createTime;
/**
......
......@@ -34,5 +34,12 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>jack</groupId>
<artifactId></artifactId>
</dependency>
</dependencies>
</project>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册