Springmvc中报data错误页面显示400报错_解决

简介: Springmvc中报data错误页面显示400报错_解决

运行后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.方法类中对定义的日期变量上添加日期转化

4fe06c5e6a234787a779946a821d97db.png


2.当配置了类型转换器,需要将实现类改为:FormattingConversionServiceFactoryBean 才可以同时支持自定义类型转换器和格式化,xml中加入

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

即可解决。

相关文章
|
1月前
|
应用服务中间件 Apache
springmvc中报错Request processing failed;
springmvc中报错Request processing failed;
|
1月前
|
Java 应用服务中间件 Maven
使用IDEA搭建SpringMVC环境,Maven导入了依赖,但是运行报错 java.lang.ClassNotFoundException
使用IDEA搭建SpringMVC环境,Maven导入了依赖,但是运行报错 java.lang.ClassNotFoundException
28 1
SpringMVC项目,什么都配好了,可就是进不了Controller,控制台也不报错,页面显示400 ?
SpringMVC项目,什么都配好了,可就是进不了Controller,控制台也不报错,页面显示400 ?
SpringMVC学习(二):访问指定页面
SpringMVC学习(二):访问指定页面
SpringMVC学习(二):访问指定页面
|
前端开发 JavaScript Java
【Spring MVC】(五)页面在 WEB-INF 下的处理方式(jsp页面、html页面)、SpringMVC 参数校验
【Spring MVC】(五)页面在 WEB-INF 下的处理方式(jsp页面、html页面)、SpringMVC 参数校验
693 0
【Spring MVC】(五)页面在 WEB-INF 下的处理方式(jsp页面、html页面)、SpringMVC 参数校验
|
前端开发 Java 数据处理
SpringMVC:认识MVC了解URL映射到页面文件全过程
SpringMVC:认识MVC了解URL映射到页面文件全过程
SpringMVC:认识MVC了解URL映射到页面文件全过程
|
Web App开发 Java
springMVC对jsp页面的数据进行校验
一. 使用注解校验 a) 引入校验依赖包 javax.validation validation-api 2.0.0.Final org.
1540 0
关于SpringMVC整合freemarker报错问题
错误信息: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'FreeMarkerConfigurer' defined in class path resource [spring-mvc.
1629 0
|
Java Spring 数据格式
springMVC4.X导入jackson三个核心包报错
本文主要是个人在利用jackson,处理json数据的时候,在spring4.x的环境下导入Jackson的jar包,一开始不知道版本问题,所以跟着视频,在网上随便下载版本,我是下载2.1的版本,之后多次运行,都是出行classnotfund的问题,我确认jar包是没问题的。
1581 0