title: Spring Validation Errors for RequestParam
body: <p>I want to pass org.springframework.validation.Errors to CodeValidator class.<br>
  But, since I am not using RequestBody/RequestPart/ModelAttribute, I cannot put Errors in method param after variable.  </p>
  
  <p>I use @RequestParam for code variable, and I want to validate that using CodeValidator class that implement org.springframework.validation.Validator.  </p>
  
  <p>Here is my code  </p>
  
  <pre><code>@RequestMapping(value = "/check-code", method = RequestMethod.POST)
  public ResponseEntity&lt;Object&gt; checkCode(@RequestParam("code") String code, Errors errors) {
      codeValidator.validate(code, errors);
      if(errors.hasErrors()) {
          return ResponseEntity.badRequest().body("Errors");
      }
      return ResponseEntity.ok("");
  }
  </code></pre>
  
  <p>and here error result for my code:<br>
  <code>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.http.ResponseEntity com.example.myapp.controller.CodeController.checkCode(java.lang.String,org.springframework.validation.BindingResult)</code><br>
  what should I do to be able using CodeValidator with @RequestParam?</p>
  
  <p>Updated:
  Code for CodeValidator</p>
  
  <pre><code>@Service
  public class CodeValidator implements Validator {
      @Override
      public void validate(Object target, Errors errors) {
          String code = ((String) target);
  
          if(code == null || code.isEmpty()) {            
              errors.rejectValue("code", "", "Please fill in Code.");
          }
      }
  }
  </code></pre>