Compare commits

..

3 Commits

Author SHA1 Message Date
ae970cb393 feat: 重载校验规则
`BasePropertyValidator#notNull`、`CollectionPropertyValidator#notEmpty` 和 `CollectionPropertyValidator#isEmpty` 提供无参的版本
2025-05-27 23:53:58 +08:00
a28a6135a8 refactor: 优化错误提示 2025-05-27 23:46:09 +08:00
9f2ade6252 refactor: 修改类型参数名称 2025-05-27 23:33:03 +08:00
7 changed files with 28 additions and 23 deletions

View File

@@ -16,7 +16,7 @@
<url>http://zhouxy.xyz</url>
<description>
Plusone Validator 是一个校验库用于构建校验规则对对象尤其是入参进行校验。API 参考自 .NET 的 FluentValidation
Plusone Validator 是一个参数校验框架,可针对 DTO 创建对应的校验器,并复用该校验器实例,对 DTO 进行校验
</description>
<properties>

View File

@@ -31,7 +31,8 @@ public class DoublePropertyValidator<T>
// ================================
public DoublePropertyValidator<T> gt(double min) {
return gt(min, String.format("The input must be greater than '%s'.", min));
return gt(min, () -> new IllegalArgumentException(
String.format("The input must be greater than '%s'.", min)));
}
public DoublePropertyValidator<T> gt(double min, String errMsg) {
@@ -58,7 +59,8 @@ public class DoublePropertyValidator<T>
// ================================
public DoublePropertyValidator<T> ge(double min) {
return ge(min, String.format("The input must be greater than or equal to '%s'.", min));
return ge(min, () -> new IllegalArgumentException(
String.format("The input must be greater than or equal to '%s'.", min)));
}
public DoublePropertyValidator<T> ge(double min, String errMsg) {
@@ -85,7 +87,8 @@ public class DoublePropertyValidator<T>
// ================================
public DoublePropertyValidator<T> lt(double max) {
return lt(max, String.format("The input must be less than '%s'.", max));
return lt(max, () -> new IllegalArgumentException(
String.format("The input must be less than '%s'.", max)));
}
public DoublePropertyValidator<T> lt(double max, String errMsg) {
@@ -112,7 +115,8 @@ public class DoublePropertyValidator<T>
// ================================
public DoublePropertyValidator<T> le(double max) {
return le(max, String.format("The input must be less than or equal to '%s'.", max));
return le(max, () -> new IllegalArgumentException(
String.format("The input must be less than or equal to '%s'.", max)));
}
public DoublePropertyValidator<T> le(double max, String errMsg) {

View File

@@ -31,7 +31,8 @@ public class IntPropertyValidator<T>
// ================================
public IntPropertyValidator<T> gt(int min) {
return gt(min, String.format("The input must be greater than '%d'.", min));
return gt(min, () -> new IllegalArgumentException(
String.format("The input must be greater than '%d'.", min)));
}
public IntPropertyValidator<T> gt(int min, String errMsg) {
@@ -58,7 +59,8 @@ public class IntPropertyValidator<T>
// ================================
public IntPropertyValidator<T> ge(int min) {
return ge(min, String.format("The input must be greater than or equal to '%d'.", min));
return ge(min, () -> new IllegalArgumentException(
String.format("The input must be greater than or equal to '%d'.", min)));
}
public IntPropertyValidator<T> ge(int min, String errMsg) {
@@ -85,7 +87,8 @@ public class IntPropertyValidator<T>
// ================================
public IntPropertyValidator<T> lt(int max) {
return lt(max, String.format("The input must be less than '%d'.", max));
return lt(max, () -> new IllegalArgumentException(
String.format("The input must be less than '%d'.", max)));
}
public IntPropertyValidator<T> lt(int max, String errMsg) {
@@ -112,7 +115,8 @@ public class IntPropertyValidator<T>
// ================================
public IntPropertyValidator<T> le(int max) {
return le(max, String.format("The input must be less than or equal to '%d'.", max));
return le(max, () -> new IllegalArgumentException(
String.format("The input must be less than or equal to '%d'.", max)));
}
public IntPropertyValidator<T> le(int max, String errMsg) {

View File

@@ -31,7 +31,8 @@ public class LongPropertyValidator<T>
// ================================
public LongPropertyValidator<T> gt(long min) {
return gt(min, String.format("The input must be greater than '%d'.", min));
return gt(min, () -> new IllegalArgumentException(
String.format("The input must be greater than '%d'.", min)));
}
public LongPropertyValidator<T> gt(long min, String errMsg) {
@@ -58,7 +59,8 @@ public class LongPropertyValidator<T>
// ================================
public LongPropertyValidator<T> ge(long min) {
return ge(min, String.format("The input must be greater than or equal to '%d'.", min));
return ge(min, () -> new IllegalArgumentException(
String.format("The input must be greater than or equal to '%d'.", min)));
}
public LongPropertyValidator<T> ge(long min, String errMsg) {
@@ -85,7 +87,8 @@ public class LongPropertyValidator<T>
// ================================
public LongPropertyValidator<T> lt(long max) {
return lt(max, String.format("The input must be less than '%d'.", max));
return lt(max, () -> new IllegalArgumentException(
String.format("The input must be less than '%d'.", max)));
}
public LongPropertyValidator<T> lt(long max, String errMsg) {
@@ -112,7 +115,8 @@ public class LongPropertyValidator<T>
// ================================
public LongPropertyValidator<T> le(long max) {
return le(max, String.format("The input must be less than or equal to '%d'.", max));
return le(max, () -> new IllegalArgumentException(
String.format("The input must be less than or equal to '%d'.", max)));
}
public LongPropertyValidator<T> le(long max, String errMsg) {

View File

@@ -18,8 +18,7 @@ package xyz.zhouxy.plusone.validator;
import java.util.function.Function;
public class ObjectPropertyValidator<T, TProperty>
extends BasePropertyValidator<T, TProperty, ObjectPropertyValidator<T, TProperty>> {
public class ObjectPropertyValidator<T, TProperty> extends BasePropertyValidator<T, TProperty, ObjectPropertyValidator<T, TProperty>> {
ObjectPropertyValidator(Function<T, TProperty> getter) {
super(getter);

View File

@@ -30,6 +30,7 @@ import com.google.common.collect.Lists;
import xyz.zhouxy.plusone.commons.collection.CollectionTools;
import xyz.zhouxy.plusone.commons.util.DateTimeTools;
import xyz.zhouxy.plusone.commons.util.StringTools;
import xyz.zhouxy.plusone.example.ExampleCommand;
import xyz.zhouxy.plusone.example.Foo;
import xyz.zhouxy.plusone.validator.BaseValidator;

View File

@@ -18,7 +18,7 @@
</modules>
<description>
Plusone Validator 是一个校验库用于构建校验规则对对象尤其是入参进行校验。API 参考自 .NET 的 FluentValidation
Plusone Validator 是一个参数校验框架,可针对 DTO 创建对应的校验器,并复用该校验器实例,对 DTO 进行校验
</description>
<properties>
@@ -27,13 +27,6 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.12.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>xyz.zhouxy.plusone</groupId>
<artifactId>plusone-dependencies</artifactId>