The use of DateTimeFormat and JsonFormat annotations

Reference link

The DateTimeFormat annotation converts the incoming string into a time format. The
incoming string needs to be consistent with the converted format. For example
@DateTimeFormat(pattern = “yyyy-MM-dd HH:mm:ss”) This is the format that needs to be converted , Then the incoming string type is 2012-12-23 12:23:23 this type

The JsonFormat annotation is to solve the time problem of parameter output. The parameter output also needs to be converted into the format we need (see the reference link above for details)

    //入参
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    //出参
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiParam("创建时间")
    private Date createTime;

Persistence or non-persistence in this life is not terrible. What I am afraid of is walking on the road of persistence alone! ! !

Guess you like

Origin blog.csdn.net/taiguolaotu/article/details/112511851