【发布时间】:2018-06-03 13:26:32
【问题描述】:
我有一个@RestController,方法如下:
@GetMapping("/getInvoices")
public List<InvoiceDto> getInvoices(@RequestParam(name="date") @DateTimeFormat LocalDate date) {
// do stuff and return a list of InvoiceDtos
}
但是当JavaScript客户端发送http://localhost:8080/getInvoices?date=Thu+Nov+30+2017+00%3A00%3A00+GMT-0600+(Central+Standard+Time)等请求时
服务器报告:
2017-12-20 16:20:03.123 WARN 10324 --- [nio-9003-exec-7] .w.s.m.s.DefaultHandlerExceptionResolver : 绑定请求失败 元素: org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: 无法将“java.lang.String”类型的值转换为所需类型 'java.time.LocalDate';嵌套异常是 org.springframework.core.convert.ConversionFailedException: 失败 从类型 [java.lang.String] 转换为类型 [@org.springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat java.time.LocalDate] 值'Thu Nov 30 2017 23:20:02 GMT-0600 (中部标准时间)';嵌套异常是 java.lang.IllegalArgumentException:值的解析尝试失败 [2017 年 11 月 30 日星期四 23:20:02 GMT-0600(中部标准时间)]
如何将日期的字符串表示形式(忽略时间部分)转换为 LocalDate?
【问题讨论】:
标签: javascript java spring spring-mvc