springboot项目后台返回时间带T的问题
程序员文章站
2024-01-01 21:36:46
实体类如下:@Data@EqualsAndHashCode(callSuper = false)@ApiModel(value="EduTeacher对象", description="讲师")public class EduTeacher implements Serializable { private static final long serialVersionUID = 1L; @ApiModelProperty(value = "讲师ID") @TableId(...
实体类如下:
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="EduTeacher对象", description="讲师")
public class EduTeacher implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "讲师ID")
@TableId(value = "id", type = IdType.ASSIGN_ID)
private String id;
@ApiModelProperty(value = "讲师姓名")
private String name;
@ApiModelProperty(value = "讲师简介")
private String intro;
@ApiModelProperty(value = "讲师资历,一句话说明讲师")
private String career;
@ApiModelProperty(value = "头衔 1高级讲师 2首席讲师")
private Integer level;
@ApiModelProperty(value = "讲师头像")
private String avatar;
@ApiModelProperty(value = "排序")
private Integer sort;
@ApiModelProperty(value = "逻辑删除 1(true)已删除, 0(false)未删除")
@Version
private Boolean isDeleted;
@ApiModelProperty(value = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime gmtCreate;
@ApiModelProperty(value = "更新时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime gmtModified;
}
接口:
@GetMapping("/findAll")
public List<EduTeacher> findAllTeacher(){
return teacherService.list();
}
返回数据:
从数据库中查询出来的数据是不带T的:
但是通过封装成java对象,并以json返回给前端的时间中是带T的:
解决方法
# application配置文件中加上如下配置:
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
#但是试了之后发现不生效
#于是我在实体类的时间属性上加上@JsonFormat,发现可行:
@JsonFormat(timezone = "GMT+8",pattern="yyyy-MM-dd HH:mm:ss")
#但是需要每个时间属性都加上,未免太麻烦
本文地址:https://blog.csdn.net/weixin_43283513/article/details/112277797