2017-12-20 1 views
0

나는이 같은 방법으로 @RestController 있습니다Spring @RequestParam의 Javascript 날짜를 LocalDate로 변환하는 방법?

2017년 12월 20일 16 :

@GetMapping("/getInvoices") 
public List<InvoiceDto> getInvoices(@RequestParam(name="date") @DateTimeFormat LocalDate date) { 
// do stuff and return a list of InvoiceDtos 
} 

그러나 자바 스크립트 클라이언트는 다음과 같은 http://localhost:8080/getInvoices?date=Thu+Nov+30+2017+00%3A00%3A00+GMT-0600+(Central+Standard+Time)

서버 보고서를 요청을 보낼 때 : 20 : 03.123 WARN 10324 --- [nio-9003-exec-7] .wsmsDefaultHandlerExceptionResolver : 요청을 바인드하지 못했습니다. 요소 : org.springframework.web.method.annot ation.MethodArgumentTypeMismatchException : 'java.lang.String'유형의 값을 필수 유형 'java.time.LocalDate'로 변환하는 데 실패했습니다. 에 실패 [java.lang.String의] 입력 형식으로 변환 [@ org.springframework.web.bind.annotation.RequestParam @ org.springframework.format : 중첩 된 예외 org.springframework.core.convert.ConversionFailedException입니다 .annotation.DateTimeFormat 값 '의 경우 11 월 30 일 2017 23:20:02 GMT-0600 (중부 표준시)'; 상자의 예외가 java.lang.IllegalArgumentException가 있습니다 : 구문 분석 시도가 값 실패 [목 십일 (30)는 그리니치 표준시 23시 20분 2초-0600 (중부 표준시) 2017]

는 어떻게이 String 표현을 변환 할 수 있습니다 날짜 (시간 구성 요소 무시)를 LocalDate로 보내시겠습니까?

답변

0

pattern 속성을 사용해보십시오 :

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