错误报告:
Field error in object 'employee' on field 'birth': rejected value [1999-6-21]; codes [typeMismatch.employee.birth,typeMismatch.birth,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [employee.birth,birth]; arguments []; default message [birth]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'birth'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.util.Date] for value '1999-6-21'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [1999-6-21]]]
Employee{id=1001, lastName='E-AA', email='aa@163.com', gender=1, department=Department [id=101, departmentName=D-AA], birth=Fri Aug 28 16:17:56 CST 2020}
错误原因:springmvc将页面提交的值转换为指定类型,即转换前可以设置类型格式(默认的是用dd/MM/yyyy)
我们则可以通过配置文件application.properties来修改这个默认格式
spring.mvc.format.date=yyyy/MM/dd
而我原来使用的
因为多加了个空格导致无法生效,且原来的默认配置覆盖掉,在输入时必须要用yyyy/MM/dd HH:mm默认的格式输入才行