JodaTime library not available - @DateTimeFormat not supported

使用spring的@DateTimeFormat来格式化Date类型时,报错:

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'modelInfoExample' on field 'birthday':
rejected value [2014-12-09];
codes [typeMismatch.modelInfoExample.birthday,typeMismatch.birthday,typeMismatch.java.util.Date,typeMismatch];
arguments [org.springframework.context.support.DefaultMessageSourceResolvable:
codes [modelInfoExample.birthday,birthday]; arguments []; default message [birthday]];
default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date'
for property 'birthday'; nested exception is org.springframework.core.convert.ConversionFailedException:
Failed to convert from type java.lang.String to type @org.springframework.format.annotation.DateTimeFormat
java.util.Date for value '2014-12-09'; nested exception is
java.lang.IllegalStateException: JodaTime library not available - @DateTimeFormat not supported]

 

很明显,确实 JodaTime 库,在pom.xml中加入其依赖,搞定:

<dependency>
			<groupId>joda-time</groupId>
			<artifactId>joda-time</artifactId>
			<version>2.6</version>
		</dependency>

 

你可能感兴趣的:(available)