Tag: spring restcontroller

如何配置使用klaxon库的spring引导

有一个klaxon库 – 用于kotlin JSON解析器 如何配置Spring Boot来使用它来创建一个REST API: @RestController class SampleController { @RequestMapping(“/test”, method = [RequestMethod.POST]) fun test(@RequestBody body:JsonObject): JsonObject { //work with body val (KLAXON object) //return KLAXON object } } @RequestBody body:JsonObject – 是一个Klaxon对象,所以我们不想使用标准的Jackson2ObjectMapperBuilder for RequestBody。 为了简单起见,我们不希望将它用于Response主体。 Post body是一些动态数据,所以我想在lib中使用Low level API ,而不是Object binding API 。

如何解析Kotlin中RestController的LocalDateTime

我试图用kotlin为我的应用程序实现一个控制器。 但是,当我提出get请求时解析日期时间格式时出现错误。 @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 […]