diff --git a/README.md b/README.md index 24f8a23..ac6d6bc 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,9 @@ class CustomerValidator extends BaseValidator { .notNull("生日不能为空") .must(LocalDate.now().minusYears(16)::isAfter, "用户必须大于16周岁"); ruleFor(Customer::getAddress).length(20, 250, "地址长度必须在20-250之间"); - ruleFor((Customer customer) -> Pair.of(customer.getVipLevel(), customer.getBirthday())) - .must(CustomerValidator::validateAge, "5级以上会员必须满18周岁"); - } - - private static boolean validateAge(Pair vipLevelAndBirthday) { - Integer vipLevel = vipLevelAndBirthday.getLeft(); - LocalDate birthday = vipLevelAndBirthday.getRight(); - return vipLevel <= 5 || LocalDate.now().minusYears(18).isAfter(birthday); + ruleFor(Customer::getVipLevel, Customer::getBirthday) + .must((vipLevel, birthday) -> vipLevel <= 5 || LocalDate.now().minusYears(18).isAfter(birthday), + "5级以上会员必须满18周岁"); } public static CustomerValidator getInstance() { @@ -73,15 +68,9 @@ class CustomerMapValidator extends MapValidator { .notNull("生日不能为空") .must(LocalDate.now().minusYears(16)::isAfter, "用户必须大于16周岁"); ruleForString("address").length(20, 250, "地址长度必须在20-250之间"); - this.>ruleFor((Map customer) -> - Pair.of(MapUtils.getInteger(customer, "vipLevel"), (LocalDate) customer.get("birthday"))) - .must(CustomerMapValidator::validateAge, "5级以上会员必须满18周岁"); - } - - private static boolean validateAge(Pair vipLevelAndBirthday) { - Integer vipLevel = vipLevelAndBirthday.getLeft(); - LocalDate birthday = vipLevelAndBirthday.getRight(); - return vipLevel <= 5 || LocalDate.now().minusYears(18).isAfter(birthday); + this.ruleForPair("vipLevel", "birthday") + .must((vipLevel, birthday) -> vipLevel <= 5 || LocalDate.now().minusYears(18).isAfter(birthday), + "5级以上会员必须满18周岁"); } public static CustomerMapValidator getInstance() {