Right now, it's a little difficult to do this automatically, but it's possible. You should use the Bean Validation Provider (JSR-303), which implements the C application. Currently this is Apache BeanValidation or Hibernate Validator 4.2 (which is in beta).
Add the selected Bean validation implementation to the classpath. This will be the JSR-303 implementation used by Spring MVC.
Secondly, annotate the method parameter with @Valid and any constraint annotations like @NonNull.
It will look something like this:
public ModelAndView getB(@Valid @NonNull @PathVariable String studyName, ...) {
That should work. Then you will need to check your Spring errors for any problems.
Alternatively, if you are not using any other Spring parameters, you can register the validator with InitBinder like this:
@InitBinder public void initBinder(WebDataBinder binder) { binder.setValidator(new StudyNameValidator()); }
Garyf
source share