How to use LocalDateTime RequestParam in Spring? I get “Failed to convert String to LocalDateTime”

后端 未结 10 1438
小蘑菇
小蘑菇 2020-11-29 02:35

I use Spring Boot and included jackson-datatype-jsr310 with Maven:


    com.fasterxml.jackson.datatype         


        
10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 02:41

    SpringBoot 2.X.X update

    If you use the dependency spring-boot-starter-web version 2.0.0.RELEASE or higher, there is no longer needed to explicitely include jackson-datatype-jsr310 dependency, which is already provided with spring-boot-starter-web through spring-boot-starter-json.

    This was resolved as Spring Boot issue #9297 and the answer is still valid and relevant:

    @RequestMapping(value = "datetime", method = RequestMethod.POST)
    public void foo(@RequestParam("dateTime") 
                    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime ldt) {
        // IMPLEMENTATION
    }
    

提交回复
热议问题