Wie zu verwenden LocalDateTime RequestParam im Frühjahr? Ich bekomme "Failed to convert String to LocalDateTime"

Ich benutze Spring Boot und enthalten jackson-datatype-jsr310 mit Maven:

<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jsr310</artifactId>
    <version>2.7.3</version>
</dependency>

Wenn ich versuche, eine RequestParam mit Java 8 Date/Time Typ,

@GetMapping("/test")
public Page<User> get(
    @RequestParam(value = "start", required = false)
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime start) {
//...
}

und testen Sie es mit dieser URL:

/test?start=2016-10-8T00:00

Bekomme ich die folgende Fehlermeldung:

{
  "timestamp": 1477528408379,
  "status": 400,
  "error": "Bad Request",
  "exception": "org.springframework.web.method.annotation.MethodArgumentTypeMismatchException",
  "message": "Failed to convert value of type [java.lang.String] to required type [java.time.LocalDateTime]; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat java.time.LocalDateTime] for value '2016-10-8T00:00'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2016-10-8T00:00]",
  "path": "/test"
}

InformationsquelleAutor Kery Hu | 2016-10-27

Schreibe einen Kommentar