Compare commits
3 Commits
245c2e962c
...
ae970cb393
Author | SHA1 | Date | |
---|---|---|---|
ae970cb393 | |||
a28a6135a8 | |||
9f2ade6252 |
@@ -16,7 +16,7 @@
|
||||
<url>http://zhouxy.xyz</url>
|
||||
|
||||
<description>
|
||||
Plusone Validator 是一个校验库,用于构建校验规则对对象(尤其是入参)进行校验。API 参考自 .NET 的 FluentValidation。
|
||||
Plusone Validator 是一个参数校验框架,可针对 DTO 创建对应的校验器,并复用该校验器实例,对 DTO 进行校验。
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
|
@@ -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) {
|
||||
|
@@ -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) {
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
9
pom.xml
9
pom.xml
@@ -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>
|
||||
|
Reference in New Issue
Block a user