javascript - java日期數(shù)據(jù)前后臺(tái)傳遞
問(wèn)題描述
是這樣的,我前臺(tái)用了ant-design的控件傳入日期類(lèi)型“2017-5”,后臺(tái)我用LocalDate類(lèi)型接收,結(jié)果報(bào)錯(cuò)了
Field error in object ’arrearsStatisticsQueryInfo’ on field ’statisticalMonth’: rejected value [2017-05]; codes [typeMismatch.arrearsStatisticsQueryInfo.statisticalMonth,typeMismatch.statisticalMonth,typeMismatch.java.time.LocalDate,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [arrearsStatisticsQueryInfo.statisticalMonth,statisticalMonth]; arguments []; default message [statisticalMonth]]; default message [Failed to convert property value of type [java.lang.String] to required type [java.time.LocalDate] for property ’statisticalMonth’; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.time.LocalDate] for value ’2017-05’; nested exception is java.time.format.DateTimeParseException: Text ’2017-05’ could not be parsed at index 2]-/api/order/arrearsStatisticsorg.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errorsField error in object ’arrearsStatisticsQueryInfo’ on field ’statisticalMonth’: rejected value [2017-05]; codes [typeMismatch.arrearsStatisticsQueryInfo.statisticalMonth,typeMismatch.statisticalMonth,typeMismatch.java.time.LocalDate,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [arrearsStatisticsQueryInfo.statisticalMonth,statisticalMonth]; arguments []; default message [statisticalMonth]]; default message [Failed to convert property value of type [java.lang.String] to required type [java.time.LocalDate] for property ’statisticalMonth’; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.time.LocalDate] for value ’2017-05’; nested exception is java.time.format.DateTimeParseException: Text ’2017-05’ could not be parsed at index 2] at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:113) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:78) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:129) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969) [spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860) [spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) [tomcat-embed-core-8.0.30.jar:8.0.30] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845) [spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) [tomcat-embed-core-8.0.30.jar:8.0.30]
我的后臺(tái)怎么樣才能接收呢?其實(shí)得到2017-5-1這一天也可以
問(wèn)題解答
回答1:用string接收然后轉(zhuǎn)成時(shí)間格式
回答2:謝邀, 看日志應(yīng)該是String轉(zhuǎn)LocalDate類(lèi)型沒(méi)有指定格式的錯(cuò)誤
在statisticalMonth這個(gè)field上加上org.springframework.format.annotation.@DateTimeFormat
回答3:時(shí)間數(shù)據(jù)序列化比較麻煩,用Date對(duì)象接收也行,需要做一些配置,用string或long比較省心!
相關(guān)文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問(wèn)題2. PHP求助,求幫忙謝謝各位3. extra沒(méi)有加載出來(lái)4. mysql - php 如何網(wǎng)址中出現(xiàn)該頁(yè)標(biāo)題?5. javascript - 按鈕鏈接到另一個(gè)網(wǎng)址 怎么通過(guò)百度統(tǒng)計(jì)計(jì)算按鈕的點(diǎn)擊數(shù)量6. javascript - 天貓首頁(yè)首屏數(shù)據(jù)來(lái)源7. 關(guān)于Mysql數(shù)據(jù)表行轉(zhuǎn)列8. django進(jìn)行數(shù)據(jù)庫(kù)的查詢(xún)9. 求救一下,用新版的phpstudy,數(shù)據(jù)庫(kù)過(guò)段時(shí)間會(huì)消失是什么情況?10. mysql - 為什么where條件中or加索引不起作用?
