Plain and simple issue:
- I would like to annotate my method parameter with some sort of annotation that would fire regular spring validation mechanism (based on
Validatorinterface) - I don’t want to include JSR303 dependency
Any ideas? I looked on @Validated but it seems that it was not created for this purpose.
Right now I do it like this:
public String req(@ModelAttribute SomeRequest request, BindingResult errors) {
validator.validate(request, errors); // This can be avoided
if (!errors.hasErrors()) {
// Valid request
return ...
} else {
// There were errors
return ...
}
}
In that case you need to create custom annotation using @interface and then use that instead of standard @Valid annotation and at runtime identify it and validate your fields accordingly. Hope this helps you. Cheers.