From the course: Complete Guide to Spring MVC
Unlock this course with a free trial
Join today to access over 24,600 courses taught by industry experts.
Validation - Spring Tutorial
From the course: Complete Guide to Spring MVC
Validation
- [Instructor] Validation. Validation in Spring MVC ensures data integrity and enforces business rules by checking the request data against predefined constraints. Spring MVC Validation capabilities integrate seamlessly with Bean Validation 3.0. Here's an example of a default validator setup. If the Bean Validation API like Hibernate Validator is available on the class path, Spring will automatically register a global local validator factory bean as the default validator. Spring will also support validation annotations like not @NotNull, @Size, and @Pattern. When using the annotation @Valid, this triggers a validation on the object like we have here in our example where we are using the @Valid annotation on user. And then some common Bean Validation annotations in addition to @NotNull, @Size, and @Pattern are also @Email. You can replace or customize the global validator by overriding the getValidator method and WebMvcConfigurer. You can also use a messageSource to customize…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.