feat(util): 添加参数验证工具类并重构系统服务
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package cn.odboy.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.odboy.framework.exception.BadRequestException;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -22,6 +23,7 @@ import jakarta.validation.ConstraintViolation;
|
||||
import jakarta.validation.Validation;
|
||||
import jakarta.validation.Validator;
|
||||
import jakarta.validation.ValidatorFactory;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.groups.Default;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@@ -61,4 +63,22 @@ public final class KitValidUtil {
|
||||
throw new BadRequestException("参数非必填");
|
||||
}
|
||||
}
|
||||
|
||||
public static void notNull(Object value, @NotNull String name, @NotNull String code) {
|
||||
if (value != null) {
|
||||
throw new BadRequestException(String.format("参数 %s(%s) 必填", name, code));
|
||||
}
|
||||
}
|
||||
|
||||
public static void isBlank(CharSequence value, @NotNull String name, @NotNull String code) {
|
||||
if (StrUtil.isNotBlank(value)) {
|
||||
throw new BadRequestException(String.format("参数 %s(%s) 非必填", name, code));
|
||||
}
|
||||
}
|
||||
|
||||
public static void notBlank(CharSequence value, @NotNull String name, @NotNull String code) {
|
||||
if (StrUtil.isBlank(value)) {
|
||||
throw new BadRequestException(String.format("参数 %s(%s) 必填", name, code));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user