public class PersonValidator implements Validator<Person> { public ValidationResult validate(Person person) { return new ValidationBuilder() .rule(new NotNullRule("name", "Name is required")) .rule(new NotEmptyRule("name", "Name cannot be empty")) .rule(new LengthRule(2, 30, "name", "Name length must be between 2 and 30 characters")) .rule(new NotNullRule("age", "Age is required")) .rule(new GreaterThanOrEqualRule(18, "age", "Age must be greater than or equal to 18")) .validate(person); } } <dependencies> <dependency> <groupId>org.fluentvalidation</groupId> <artifactId>fluentvalidation</artifactId> <version>2.0.15</version> </dependency> </dependencies>


上一篇:
下一篇:
切换中文