If you don't accumulate steps, you won't reach thousands of miles; if you don't accumulate small streams, you won't be able to form rivers and seas ----- to the struggling self
Scenes:
The front-end transmits date parameters to the back-end, and the back-end receives problems. I will summarize this low-level problem once I encounter it.
Documentation reference:
Front-end date format: yyyy-MM-dd HH:mm:ss
Correct way:
Method 1: The backend uses the date type to receive
Method 2: The backend date type field only uses @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") to receive
wrong way:
Method 1: Only use @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") to receive the backend date type field, and report an error directly when requesting.
Use the @DateTimeFormat annotation correctly
Method 1: Add @RequestBody to the receiving object and use it with @JsonFormat
Method 2: The receiving object does not add @RequestBody and the Date type field only uses @DateTimeFormate
Note: The request body used here is form-date . If you use the request body json, you will not receive data if you use the following request backend date type field
Summarize:
When the front-end date string is passed to the back- end when the back-end receives it with a date type field
1. The receiving object uses @RequestBody with @DateTimeFormat and @JsonForma
2. The receiving object uses @RequestBody with @JsonForma to convert the date string into a date format
3. The receiving object does not need to be decorated with @RequestBody, the form-data type of the request body (json type is not allowed) can pass @DateTimeFormat
Convert date string to date format