我在我的Spring应用程序REST端点,看起来像这样ZonedDateTime如PathVariable在弹簧安置RequestMapping
@RequestMapping(value="/customer/device/startDate/{startDate}/endDate/{endDate}", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public Page<DeviceInfo> getDeviceListForCustomerBetweenDates(@PathVariable ZonedDateTime startDate, @PathVariable ZonedDateTime endDate, Pageable pageable) {
... code here ...
}
我试图传递路径变量既是毫秒和秒。不过,我得到以下异常两种方式:
"Failed to convert value of type 'java.lang.String' to required type 'java.time.ZonedDateTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @org.springframework.web.bind.annotation.PathVariable java.time.ZonedDateTime for value '1446361200'; nested exception is java.time.format.DateTimeParseException: Text '1446361200' could not be parsed at index 10"
是否有人可以解释我是如何可以传递(无论是作为秒或毫秒)的字符串,如1446361200,并把它转换为ZonedDateTime?
或者是作为String传递的唯一方法,然后自己进行转换?如果是的话,是否有一种通用的方法来处理类似设计的多种方法?
'ZonedDateTime'是相对较新的,并且Spring可能尚未更新以直接支持它。请参阅JasonZ的回答,寻找解决方法。 – Powerlord