Ich habe einen einfache Feder-Controller:Set default/globales Datumsformat in Spring MVC ISO 8601
@RequestMapping(value="", method=RequestMethod.GET)
public void search(MyDTO dto) {
// ...
}
Und MyDTO
:
public class MyDTO {
private DateTime date;
public DateTime getDate() { return date; }
public void setDate(DateTime date) { this.date = date; }
}
Ich kann wirklich die Controller-Methode mit meinem lokalen Datum nennen Format: 03.10.2013 01:00
, z GET http://localhost:8080/test?date=03.10.2013 01:00
Aber ich möchte Anwendung breit ISO 8601 Datumsformat, zB: 2007-03-01T13:00:00Z
Wenn ich ISO-Format erhalte ich folgende Fehlermeldung:
Failed to convert property value of type 'java.lang.String' to required type
'org.joda.time.DateTime' for property 'date'; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to convert
from type java.lang.String to type org.joda.time.DateTime for value
'2013-09-25T23:05:18.000+02:00'; nested exception is
java.lang.IllegalArgumentException: Invalid format:
"2013-09-25T23:05:18.000+02:00" is malformed at "13-09-25T23:05:18.000+02:00"
Es muss einen Weg geben, um es zu ändern für java.util.Date
und all diese Joda Date and Time Container.
Ich fand nur die addFormatters(FormatterRegistry registry)
Methode innerhalb WebMvcConfigurationSupport
, aber ich weiß nicht wirklich, wie man es benutzt.