This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.12.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>com.fasterxml.jackson.module</groupId> | |
<artifactId>jackson-module-kotlin</artifactId> | |
<version>2.12.1</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@CustomGoogleEmailConstraint | |
private String email; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomGoogleEmailValidator implements ConstraintValidator<CustomGoogleEmailConstraint, String> { | |
@Override | |
public void initialize(CustomGoogleEmailConstraint email) { } | |
@Override | |
public boolean isValid(String email, ConstraintValidatorContext constraintValidatorContext) { | |
return email != null && email.matches("^[a-zA-Z0–9.]+@gmail.com"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Documented | |
@Constraint(validatedBy = CustomGoogleEmailValidator.class) | |
@Target({ ElementType.METHOD, ElementType.FIELD }) | |
@Retention(RetentionPolicy.RUNTIME) | |
public @interface CustomGoogleEmailConstraint { | |
String message() default "The email must have \"@gmail.com\" extension"; | |
Class[] groups() default {}; | |
Class[] payload() default {}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.hibernate</groupId> | |
<artifactId>hibernate-validator</artifactId> | |
<version>6.0.10.Final</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NotEmpty(message = "The Full Name can't be null") | |
@Size(min = 5, message = "{Size.Person.FullName}") | |
private String fullName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="alert alert-warning" th:if="${#fields.hasErrors('age')}" th:errors="*{age}"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GetMapping("/add") | |
public String showAddPersonForm(Person person) { | |
return "add-person"; | |
} | |
@PostMapping("/add") | |
public String addPerson(@Valid Person person, BindingResult result, Model model) { | |
if (result.hasErrors()) { | |
return "add-person"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Repository | |
public interface PersonRepository extends JpaRepository<Person, Long> { } |
NewerOlder