From 5b5d7b50d620444ffe0ef40d866f23e66033a6b2 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Fri, 25 Jul 2025 17:34:19 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=E7=A4=BA=E4=BE=8B=20?= =?UTF-8?q?(plusone/plusone-validator#18=20from=20gitea)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ZhouXY108 Co-committed-by: ZhouXY108 --- README.md | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) 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() {