当前位置:   article > 正文

Springmvc中报data错误页面显示400报错_解决_24-jun-2023 15:27:53.110 警告 [http-nio-8080-exec-3]

24-jun-2023 15:27:53.110 警告 [http-nio-8080-exec-3] org.springframework.web

运行后tomcat显示报错:
21-Sep-2022 09:20:47.318 警告 [http-nio-8080-exec-5] org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.logException Resolved [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object ‘user’ on field ‘birthday’: rejected value [2001-10-10]; codes [typeMismatch.user.birthday,typeMismatch.birthday,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.birthday,birthday]; arguments []; default message [birthday]]; default message [Failed to convert property value of type ‘java.lang.String’ to required type ‘java.util.Date’ for property ‘birthday’; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.format.annotation.DateTimeFormat java.util.Date] for value ‘2001-10-10’; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2001-10-10]]]
21-Sep-2022 09:20:58.122 警告 [http-nio-8080-exec-7] org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.logException Resolved [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object ‘user’ on field ‘birthday’: rejected value [2001/10/10]; codes [typeMismatch.user.birthday,typeMismatch.birthday,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.birthday,birthday]; arguments []; default message [birthday]]; default message [Failed to convert property value of type ‘java.lang.String’ to required type ‘java.util.Date’ for property ‘birthday’; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.format.annotation.DateTimeFormat java.util.Date] for value ‘2001/10/10’; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2001/10/10]]]

ssm学习过程中,有时候要用到输入日期类型
因为当你输入日期时候,需要用到类型的转换,这里你可以自定义一个日期时间类型,也可以使用maven中自带的

1.方法类中对定义的日期变量上添加日期转化
在这里插入图片描述
2.当配置了类型转换器,需要将实现类改为:FormattingConversionServiceFactoryBean 才可以同时支持自定义类型转换器和格式化,xml中加入

 <bean class="org.springframework.format.support.FormattingConversionServiceFactoryBean" id="conversionService">
    </bean>
  • 1
  • 2

即可解决。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/657810
推荐阅读
相关标签
  

闽ICP备14008679号