关于java bean在后台\转化为json交给前台时间类型格式调整的方法:
- 首先要引入fastjson依赖。
- 在实体类上使用注解: @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8"),这里是精确到秒,如果只精确到天,就把上面注解的HH:mm:ss去掉。
package com.xjzt.waimai.pojo.weChatUser;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.type.Alias;
import java.io.Serializable;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Alias("weCharUser")
public class WeCharUser implements Serializable {
private String openId;
private String nickName;
private String gender;
private String province;
private String city;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date lastVisitTime;
}