Mybatis-plus 查詢數據時間格式化問題

默認返回這種格式

[
{
"id": 2,
"code": "ancd",
"date": "2021-09-03T01:53:10.000+00:00"
}
]

只需在屬性上添加一個對應代碼

public class Address implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private String code;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
    private Date date;


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @Override
    public String toString() {
        return "Address{" +
        "id=" + id +
        ", code=" + code +
        ", date=" + date +
        "}";
    }
}

返回對應的結果

[
{
"id": 2,
"code": "ancd",
"date": "2021-09-03 09:53:10"
}
]

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章