如何将Spring@RequestParam的Javascript日期转换为LocalDate?
我有一个如何将Spring@RequestParam的Javascript日期转换为LocalDate?,javascript,java,spring,spring-mvc,Javascript,Java,Spring,Spring Mvc,我有一个@RestController,方法如下: @GetMapping("/getInvoices") public List<InvoiceDto> getInvoices(@RequestParam(name="date") @DateTimeFormat LocalDate date) { // do stuff and return a list of InvoiceDtos } @GetMapping(“/getInvoices”) 公共列表getInvoices(
@RestController
,方法如下:
@GetMapping("/getInvoices")
public List<InvoiceDto> getInvoices(@RequestParam(name="date") @DateTimeFormat LocalDate date) {
// do stuff and return a list of InvoiceDtos
}
@GetMapping(“/getInvoices”)
公共列表getInvoices(@RequestParam(name=“date”)@DateTimeFormat LocalDate日期){
//完成任务并返回InvoicedTo列表
}
但是当JavaScript客户端发送一个请求时,例如
服务器报告:
2017-12-20 16:20:03.123警告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]值为'2017年11月30日星期四23:20:02 GMT-0600
(中央标准时间);嵌套异常是
java.lang.IllegalArgumentException:解析值的尝试失败
[2017年11月30日星期四23:20:02 GMT-0600(中央标准时间)]
如何将日期的字符串表示形式(忽略时间组件)转换为LocalDate 尝试使用
模式
属性:
@DateTimeFormat(pattern="E MMM dd yyyy HH:mm:ss 'GMT'Z")