Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 多部分文件的自定义验证程序_Spring_Spring Mvc_Spring Boot_Spring Validator - Fatal编程技术网

Spring 多部分文件的自定义验证程序

Spring 多部分文件的自定义验证程序,spring,spring-mvc,spring-boot,spring-validator,Spring,Spring Mvc,Spring Boot,Spring Validator,我正在尝试使用Spring验证器构建一个自定义验证器来检查多部分文件,但我面临这个问题: An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments to which they apply: public org.springframework.web.contex

我正在尝试使用
Spring
验证器构建一个自定义验证器来检查
多部分文件
,但我面临这个问题:

 An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments to which they apply: public org.springframework.web.context.request.async.DeferredResult br.com.mobtrack.api.resource.CityResource.uploadImage(org.springframework.web.multipart.MultipartFile,org.springframework.validation.BindingResult)
这是我的验证器类:

@Component
public class MultipartFileValidator implements Validator{

    @Override
    public boolean supports(Class<?> aClass) {
        return MultipartFile.class.isAssignableFrom(aClass);
    }

    @Override
    public void validate(Object o, Errors errors) {
        MultipartFile file = (MultipartFile) o;
       if (file == null || file.isEmpty()){
           errors.reject("image","send a valid image. );
       }
    }
}
BindingResult参数应在模型属性、@RequestBody或@RequestPart参数之后立即声明

它与验证器无关。它似乎与控制器在一起


它似乎在告诉你这个问题。您需要使用@RequestBody或@RequestPart注释来告诉它在哪里查找要绑定的数据。

尝试了如何使用它们。它们不在提供的示例中。它们是否紧跟在消息中描述的模型之后?你那样做的时候发生了什么?相同的错误错误是否发生了更改?仅仅说“不起作用”或“出错”并不能给任何人带来任何可以合作的东西。
 @PostMapping("/image")
    public DeferredResult<String> uploadImage(@Valid MultipartFile image, BindingResult result) {

        if (result.hasErrors()) {
            throw new ImageNotFoundException("test");
        } else {
            DeferredResult<String> deferredResult = new DeferredResult<>();

            Thread thread = new Thread(new ImageStorageRunnable(image, deferredResult, imageStorage));
            thread.start();
            return deferredResult;
        }
    }