1.dto
import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import java.io.Serializable; import java.util.Date; /** * @author: htdd * @date: 2022/1/7 11:15 */ @Data public class TestDTO implements Serializable { @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") private Date createTime; }
2.controller
@PostMapping("test") public JsonData test(HttpServletRequest request, @RequestBody TestDTO dto) { return JsonData.buildSuccess("success"); }
3. An error is reported after a postman request
Postman request
Background error reporting
Error reporting reason:
The general meaning is that the time format does not meet the requirements. After checking the document, the default conversion format for time is
"yyyy-MM-dd'T'HH:mm:ss.SSSZ" "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" "EEE, dd MMM yyyy HH:mm:ss zzz" "yyyy-MM-dd"
Solution:
Unified configuration in configuration file
spring.jackson.time-zone=GMT+8 spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
4. Postman requests again and the conversion is successful
Similar Posts:
- JAVA Error: Failed to convert property value of type ‘java.lang.String‘ to required type ‘java.util.Date
- [Solved] java.lang.IllegalArgumentException: Cannot format given Object as a Date
- ora-01810 format code appears twice
- On the non thread safety problem of simpledateformat and its solution
- Get the time value from the database and report an error: Java sql. Timestamp cannot be cast to java. lang.Long
- [How to Solve] Failed to convert value of type ‘java.lang.String’ to required type ‘java.util.Date’;
- The full calendar obtains the events report uncaught type error: callback is not a function from the background
- [Solved] Error: org.springframework.validation.BeanPropertyBindingResult
- HDFS: How to Operate API (Example)
- How to solve the problem of “no observations” in Stata?