日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java date iso,使用DateTimeFormat.ISO.DATE配置Jackson而不是工作

發(fā)布時間:2024/1/8 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java date iso,使用DateTimeFormat.ISO.DATE配置Jackson而不是工作 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我想在每次請求日期時使用DateTimeFormat.ISO.DATE配置Jackson,例如:

@RequestMapping(value = "income")

public ResponseEntity calculateIncome(

@RequestParam(value = "companyName") String companyName,

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)

@RequestParam(value = "startDate") LocalDate startDate,

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)

@RequestParam(value = "endDate") LocalDate endDate

)

我已經(jīng)嘗試過在JacksonConfig中設(shè)置它

mapper.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

要么

mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);

要么

mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);

甚至在我試過的application.properties中

spring.jackson.serialization.write_dates_as_timestamps=true

我正在使用spring-boot機智跟隨依賴項

org.springframework.boot

spring-boot-starter-web

1.5.10.RELEASE

com.fasterxml.jackson.datatype

jackson-datatype-jsr310

${jackson.version}

我只是不想重復(fù)相同的@DataTimeFormat,但沒有它,我仍然會收到錯誤:

in IntelJ

2018-03-01 15:35:05.539 WARN 8168 --- [nio-8080-exec-1] .wsmsDefaultHandlerExceptionResolver:無法綁定請求元素:org.springframework.web.method.annotation.MethodArgumentTypeMismatchException:轉(zhuǎn)換失敗類型'java.lang.String'的值為必需類型'java.time.LocalDate';嵌套異常是org.springframework.core.convert.ConversionFailedException:無法從類型[java.lang.String]轉(zhuǎn)換為類型[@ org.springframework.web.bind.annotationParam java.time.LocalDate]的值為'2018 -02-28' ;嵌套異常是java.lang.IllegalArgumentException:解析嘗試失敗的值[2018-02-28]

Postman

{

"timestamp": 1519914905555,

"status": 400,

"error": "Bad Request",

"exception": "org.springframework.web.method.annotation.MethodArgumentTypeMismatchException",

"message": "Failed to convert value of type 'java.lang.String' to required type 'java.time.LocalDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestParam java.time.LocalDate] for value '2018-02-28'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2018-02-28]",

"path": "/incVat"

}

要么

{

"timestamp": "2018-03-01T15:36:44.823+0000",

"status": 400,

"error": "Bad Request",

"exception": "org.springframework.web.method.annotation.MethodArgumentTypeMismatchException",

"message": "Failed to convert value of type 'java.lang.String' to required type 'java.time.LocalDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestParam java.time.LocalDate] for value '2018-02-28'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2018-02-28]",

"path": "/incVat"

}

總結(jié)

以上是生活随笔為你收集整理的java date iso,使用DateTimeFormat.ISO.DATE配置Jackson而不是工作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。