zl程序教程

您现在的位置是:首页 >  后端

当前栏目

springboot出错误Validation failed for object='employee'. Error count: 1

SpringBoot错误Failed Error for &# 39 object
2023-09-27 14:21:42 时间

链接:https://blog.csdn.net/luo609630199/article/details/81746192

今天在学习spring boot时发现无论如何都不能提交表单,刚开始以为时前端页面错误,但是改了好几遍,弄了几个小时,依然不行,左后发现是后端的问题 

错误如下:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Thu Aug 16 17:03:27 CST 2018

There was an unexpected error (type=Bad Request, status=400).

Validation failed for object='employee'. Error count: 1

解决方法如下:

在形参后面加上BindingResult bindingResult后解决

 

 

 

实出现 Validation failed for object='employee错误时,还有可能是因为表单提交的数据格式不对,这是就容易抱着中验证错误

 

提交的数据格式不对:生日:日期;

2017-12-12;2017/12/12;2017.12.12;

日期的格式化;SpringMVC将页面提交的值需要转换为指定的类型;

2017-12-12---Date; 类型转换,格式化;

默认日期是按照/的方式的,如果按照这个默认格式提交不加BindingResult bindingResult也是可以的;

这次我把形参中的BindingResult bindingResult去掉就能提交成功啦,所以需要我们自己写代码转换默认的日期格式

 

下面我们就来自定义我们自己的日期格式

在application.properties文件中配置下面代码,就能修改springboot的默认配置

spring.mvc.date-format=yyyy-MM-dd