2017-08-21 3 views
-2

私はkotlinを使ってアプリケーション用のコントローラを実装しようとしています。しかし、取得リクエストをするときにdatetime形式を解析するときにエラーが発生します。KotlinのRestControllerからLocalDateTimeをパースする方法

@RestController 
@RequestMapping("/api/records") 
class RecordController(val recordService: RecordService) { 

    @GetMapping("details") 
    fun getRecordDetail(
    @RequestParam recordId: Int, 
    @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) dateTime: LocalDateTime): RecordDto { 
    return recordService.getRecordDetails(recordId, dateTime) 
    } 
} 

エラーが

Failed to convert value of type 'java.lang.String' to required type 'java.time.LocalDateTime'; nested exception is org.springframework.core.convert.ConversionFailedException: 
Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat java.time.LocalDateTime] for value '2017-08-21T00:00:000.00'; nested exception is java.lang.IllegalArgumentException: 
Parse attempt failed for value [2017-08-21T00:00:000.00]" 

残りのAPIは、dateTimeのパラメータを指定せずに正常に動作しています。

答えて

0

これは、指定したISO-dateと互換性のない形式で値を指定したためです。ここで

あなたの価値(あなたの側から多分ちょうど「誤植」)と作業値

2017-08-21T00:00:000.00 (yours) 
2017-08-21T00:00:00.000 (working) 

有効な二ミリ秒の値を提供していることを確認してください。

+0

申し訳ありませんが、私の間違いです。私は正しくチェックしていない。本当にありがとう –

関連する問題