There was an unexpected error (type=Bad Request, status=400). Validation failed for object='employee

 

There was an unexpected error (type=Bad Request, status=400). Validation failed for object='employee

上面提示了employee封装的对象不正确。400表示无法进行类型转换。

查看你提交表单的那个页面每一项的name属性是否与你实体类中的属性相对应。

There was an unexpected error (type=Bad Request, status=400). Validation failed for object='employee

经过验证之后发现javabean属性都是正确的。

然后我们打开F12,点击修改

There was an unexpected error (type=Bad Request, status=400). Validation failed for object='employee

发现所提交的都是正确的

以上都正确后,我们需要着重检查一下Date这个类型,也就是上面的birth这个属性,在springboot中会有默认的日期格式,我们搜索WebMvcAutoConfiguration ,在里面搜索Formatter这个默认的日期格式处理(419行),

There was an unexpected error (type=Bad Request, status=400). Validation failed for object='employee

然后点进去圈中那个,

There was an unexpected error (type=Bad Request, status=400). Validation failed for object='employee

--这里可以设置日期的格式,,,默认是1997/11/23   斜线分割

There was an unexpected error (type=Bad Request, status=400). Validation failed for object='employee

我们可以设置指定的日期格式在我们的配置文件中

There was an unexpected error (type=Bad Request, status=400). Validation failed for object='employee

看到这里估计大家已经看到我的问题所在了,那就是多了一道"-",改成正确的格式,重新测试---》成功。