javascript - données de date Java transmises avant et après
过去多啦不再A梦
过去多啦不再A梦 2017-05-17 09:56:05
0
3
661

Ça y est. J'ai utilisé le contrôle ant-design dans le frontend pour passer le type de date "2017-5", et j'ai utilisé le type LocalDate pour le recevoir dans le backend, mais une erreur a été signalée

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/arrearsStatistics
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
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]
    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]

Comment mon background peut-il le recevoir ? En fait, vous pouvez également obtenir le jour 2017-5-1

过去多啦不再A梦
过去多啦不再A梦

répondre à tous(3)
阿神

Utilisez une chaîne pour la recevoir puis convertissez-la au format horaire

淡淡烟草味

Merci pour l'invitation. En regardant le journal, cela devrait être une erreur que le type String à LocalDate n'ait pas de format spécifié StringLocalDate类型没有指定格式的错误

statisticalMonth这个field上加上org.springframework.format.annotation.@DateTimeFormat.

Ajoutez org.springframework.format.annotation.@DateTimeFormat au champ statisticalMonth🎜
大家讲道理

La sérialisation des données temporelles est gênante. Vous pouvez également utiliser l'objet Date pour les recevoir. Vous devez effectuer une certaine configuration. Il est plus simple d'utiliser une chaîne ou un long !

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!