Add a method to Java controller to solve the problem
/**
* Solution: Failed to convert value of type 'java.lang.String' to required type 'java.util;
* The main reason for this error is that the required type in the Controller class is Date, but the type passed on the page side is String, which eventually leads to this error.
*/
@InitBinder
public void initBinder(WebDataBinder binder, WebRequest request) {
//convert the date Note that the conversion here should always be in the same format as the string passed in, e.g. 2015-9-9 should be yyyy-MM-dd
DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));// CustomDateEditor is a custom date editor
}
Read More:
- [Solved] Scala error: type mismatch; found : java.util.List[?0] required: java.util.List[B]
- [Solved] SpringBoot Date Convert Error: JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime`
- [How to Solve Error]java.util.Date cannot be cast to java.sql.Date
- [Solved] Java.lang.ClassCastException: [Ljava.lang.Long; cannot be cast to java.util.List
- [Solved] No validator could be found for constraint ‘javax.validation.constraints.NotBlank’ validating type ‘java.lang.String’
- How to convert a Java string into a number (stringtonumber)
- [Solved] swagger Docmentation Access Error: Illegal DefaultValue 1024 for parameter type integer, java.lang.NumberFormatException
- [Solved] stream Convert list to map Error: java.lang.IllegalStateException: Duplicate key
- How to get the current time in java time string
- [Solved] Java.lang.IllegalStateException: Type handler was null on parameter mapping for property ‘__frch_it
- Explicit and implicit conversion of Java data type
- [Solved] Hibernate Error: java.lang.StackOverflowError at java.lang.Integer.toString(Integer.java:402)
- JAVA: How to Convert PDF from Color to Grayscale
- Solve the use of declaration transactions in spring java.lang.NoClassDefFoundError: org/aspectj/util/PartialOrder$PartialComparable
- [Solved] Java.util.linkedhashmap cannot be cast to entity class
- [Solved] JAVA fx Error: java.lang.instrument ASSERTION FAILED ***: “!errorOutstanding“ with message transform
- [Solved] Swagger Startup Error: java.lang.NumberFormatException: For input string: ““
- JAVA 8: How to Convert List to Map
- Java Error: No enclosing instance of type Main is accessible. Must qualify the allocation with an encl
- [Solved] Failed to instantiate java.util.List using constructor NO_CONSTRUCTOR with arguments