I use the Spring Framework for my services API and org.joda.time.DateTimefor datetime parsing. In particular, I use ISOFormatter.dateOptionalTimeParser(), which allows users to flexibly use only the date or date and time, which is a requirement.
Believe me, I saw all these related questions that I can already say, people are going to point me, for example. and so on
I used to take the date as String, and then process it using the joda formatting mentioned above at the service level, but now I want to add the request check to the controller, which means that if the request is syntactically incorrect, the request should not even go to the service level.
I tried using several options @DateTimeFormat(iso = ISO.DATE_TIME)as well as specifying patternString in a no-luck format.
@RequestMapping(value = URIConstants.TEST_URL, method = RequestMethod.GET)
public @ResponseBody String getData(@RequestParam(required = false) DateTime from,
@RequestParam(required = false) DateTime to) {
return dataService.fetchDataFromDB(from, to);
}
What should I do to ensure that the date I receive from the user matches the format ISO 8601 dateOptionalTime? Can I apply multiple patterns to implement this?
source
share