如何为Spring @RequestParam将Javascript日期转换为LocalDate?

时间:2017-12-20 22:30:31

标签: javascript java spring spring-mvc

我有一个 File "predictstocks.py", line 21 svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0,1) SyntaxError: non-keyword arg after keyword arg ,其方法如下:

@RestController

但是当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&#39 ;;嵌套异常是   org.springframework.core.convert.ConversionFailedException:失败   从类型[java.lang.String]转换为type   [@ org.springframework.web.bind.annotation.RequestParam   @ org.springframework.format.annotation.DateTimeFormat   java.time.LocalDate] for value' Thu Nov 30 2017 23:20:02 GMT-0600   (中央标准时间)&#39 ;;嵌套异常是   java.lang.IllegalArgumentException:解析尝试失败的值   [2017年11月30日星期四23:20:02 GMT-0600(中央标准时间)]

如何将日期的String表示(忽略时间组件)转换为LocalDate?

1 个答案:

答案 0 :(得分:0)

尝试使用pattern属性:

@DateTimeFormat(pattern="E MMM dd yyyy HH:mm:ss 'GMT'Z")