About the problem of returning JavaDate data to the front-end variable number

I don't know why, all the data items displayed on the front end are correct, only the time item is very strange, it is a string of numbers, and this number can't be found in the database...

Then I debugged everything from the service to the controller in the backend, and found that the data was correct, and all I took was time.

Later, Baidu learned that when the backend returned json data, it used its own serialization mechanism to turn the time into a long number, just like the display above.

 

Then here's something to use:

@JsonFormat, its function is to automatically convert Date object data into a correctly formatted string when outputting parameters

 

Effect:

 

Then I learned through Du Niang, there is also a note

@DateTimeFormat

This is used to convert the string variable passed from the foreground to the background to Date type. The request message only needs to pass in the yyyymmddhhmmss string, and it will be automatically converted to Date type data

However, there is also information that @JsonFormat can not only complete the type conversion from the background to the foreground parameter transfer, but also realize the type conversion from the foreground to the background. When the content-type is application/json, the pattern of @JsonFormat is preferred for type conversion. without using @DateTimeFormat for type conversion.

 

Regarding the issue of entering the ginseng, I will not study it here, and I will have time to study it in the future.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324937006&siteId=291194637