Validation failed for argument [0]

Posted ITdfq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Validation failed for argument [0]相关的知识,希望对你有一定的参考价值。


出现原因:@RequestBody @Validated 同时使用,如果实体类参数为null 就会抛出异常
解决办法:BindingResult result 进行接收,对错误进行处理
例如: (@RequestBody @Validated Student student,BindingResult result)

 log.info("接受的参数为: 【{}】", JSON.toJSONString(student));
        if (result.hasErrors()) {
            FieldError fieldError = result.getFieldError();
            if (fieldError != null) {
                log.info(" msg: 【{}】", fieldError.getDefaultMessage());
               
            }
       }

以上是关于Validation failed for argument [0]的主要内容,如果未能解决你的问题,请参考以下文章

Validation failed for one or more entities. See 'EntityValidationErrors' property for more d

Validation failed for one or more entities. See 'EntityValidationErrors' property for more d

报错Validation failed for object='userLogin'. Error count: 1

Validation failed for one or more entities. See ‘EntityValidationErrors

“Validation failed for one or more entities”异常的解决办法

spring boot 表单的实体提交错误:Validation failed for object='book'. Error count: 2