diff --git a/airpower-core/pom.xml b/airpower-core/pom.xml
index b9d304a850b98afd999d9b5b9fee6d776ce73950..3b906d2dc1a7a32cecfff9756ff80fdbcd92ad21 100644
--- a/airpower-core/pom.xml
+++ b/airpower-core/pom.xml
@@ -5,10 +5,10 @@
cn.hamm
airpower
- 2.0.4
+ 2.0.5
airpower-core
- 2.0.4
+ 2.0.5
airpower-core
AirPower is a fast backend development tool based on SpringBoot3 and JPA. It's the core of AirPower.
diff --git a/airpower-core/src/main/java/cn/hamm/airpower/interceptor/ExceptionInterceptor.java b/airpower-core/src/main/java/cn/hamm/airpower/interceptor/ExceptionInterceptor.java
index 88479e77c58eec81c01f49fbe1828ff6cfae4c40..f0b88f970f8d6d9f3b218fd48470f65d36037363 100644
--- a/airpower-core/src/main/java/cn/hamm/airpower/interceptor/ExceptionInterceptor.java
+++ b/airpower-core/src/main/java/cn/hamm/airpower/interceptor/ExceptionInterceptor.java
@@ -63,12 +63,9 @@ public class ExceptionInterceptor {
return Json.error(ServiceError.PARAM_INVALID);
}
List errors = result.getFieldErrors();
- for (FieldError error : errors) {
- stringBuilder.append(String.format(
- MessageConstant.MESSAGE_AND_DESCRIPTION, error.getDefaultMessage(), error.getField()
- ));
- break;
- }
+ errors.stream().findFirst().ifPresent(error -> stringBuilder.append(String.format(
+ MessageConstant.MESSAGE_AND_DESCRIPTION, error.getDefaultMessage(), error.getField()
+ )));
return Json.error(ServiceError.PARAM_INVALID, stringBuilder.toString());
}
@@ -80,12 +77,9 @@ public class ExceptionInterceptor {
log.error(exception.getMessage());
StringBuilder stringBuilder = new StringBuilder();
Set> errors = exception.getConstraintViolations();
- for (ConstraintViolation> error : errors) {
- stringBuilder.append(String.format(
- MessageConstant.MESSAGE_AND_DESCRIPTION, error.getMessage(), error.getInvalidValue().toString()
- ));
- break;
- }
+ errors.stream().findFirst().ifPresent(error -> stringBuilder.append(String.format(
+ MessageConstant.MESSAGE_AND_DESCRIPTION, error.getMessage(), error.getInvalidValue().toString()
+ )));
return Json.error(ServiceError.PARAM_INVALID, stringBuilder.toString());
}
@@ -107,7 +101,6 @@ public class ExceptionInterceptor {
@ExceptionHandler(NoHandlerFoundException.class)
public Json notFoundHandle(@NotNull NoHandlerFoundException exception, HttpServletResponse response) {
log.error(exception.getMessage());
-
if (Configs.getServiceConfig().isEnableDocument()) {
String[] arr = exception.getRequestURL().split(Constant.SLASH);
if (arr.length > 1) {
@@ -115,9 +108,7 @@ public class ExceptionInterceptor {
boolean result = ApiDocument.writeEntityDocument(packageName, response);
if (!result) {
response.reset();
- return Json.error(ServiceError.API_SERVICE_UNSUPPORTED);
}
-
}
}
return Json.error(ServiceError.API_SERVICE_UNSUPPORTED);
@@ -154,7 +145,8 @@ public class ExceptionInterceptor {
log.error(ServiceError.REQUEST_CONTENT_TYPE_UNSUPPORTED.getMessage(), exception);
}
return Json.error(ServiceError.REQUEST_CONTENT_TYPE_UNSUPPORTED, String.format(
- MessageConstant.ONLY_CONTENT_TYPE_JSON_SUPPORTED, Objects.requireNonNull(exception.getContentType()).getType()
+ MessageConstant.ONLY_CONTENT_TYPE_JSON_SUPPORTED,
+ Objects.requireNonNull(exception.getContentType()).getType()
));
}
diff --git a/airpower-core/src/main/java/cn/hamm/airpower/model/Json.java b/airpower-core/src/main/java/cn/hamm/airpower/model/Json.java
index 2029112752c1a6bce67fdbbb4d16cabb206e6909..b4f11f18fa952503a664a4251c258c6f2171516e 100644
--- a/airpower-core/src/main/java/cn/hamm/airpower/model/Json.java
+++ b/airpower-core/src/main/java/cn/hamm/airpower/model/Json.java
@@ -41,11 +41,13 @@ public class Json {
*/
@Description("错误代码")
private int code = Constant.JSON_SUCCESS_CODE;
+
/**
* 错误信息
*/
@Description("错误信息")
private String message = Constant.JSON_SUCCESS_MESSAGE;
+
/**
* 返回数据
*/
diff --git a/airpower-core/src/main/java/cn/hamm/airpower/open/OpenRequest.java b/airpower-core/src/main/java/cn/hamm/airpower/open/OpenRequest.java
index c2a730833a874d8f8c017072f64a18e9f0f547df..5323009857c185c5328ce83a261207d3796cee9b 100644
--- a/airpower-core/src/main/java/cn/hamm/airpower/open/OpenRequest.java
+++ b/airpower-core/src/main/java/cn/hamm/airpower/open/OpenRequest.java
@@ -91,7 +91,9 @@ public class OpenRequest {
* @return 签名后的字符串
*/
public final @org.jetbrains.annotations.NotNull String sign() {
- return DigestUtils.sha1Hex(this.openApp.getAppSecret() + this.appKey + this.version + this.timestamp + this.nonce + this.content);
+ return DigestUtils.sha1Hex(
+ this.openApp.getAppSecret() + this.appKey + this.version + this.timestamp + this.nonce + this.content
+ );
}
/**
@@ -120,16 +122,15 @@ public class OpenRequest {
);
try {
switch (appArithmeticType) {
- case AES:
- request = Utils.getAesUtil().setKey(this.openApp.getAppSecret()).decrypt(request);
- break;
- case RSA:
- request = Utils.getRsaUtil().setPrivateKey(openApp.getPrivateKey()).privateKeyDecrypt(request);
- break;
- case NO:
- break;
- default:
- throw new ServiceException("解密失败,不支持的加密算法类型");
+ case AES -> request = Utils.getAesUtil()
+ .setKey(this.openApp.getAppSecret())
+ .decrypt(request);
+ case RSA -> request = Utils.getRsaUtil()
+ .setPrivateKey(openApp.getPrivateKey())
+ .privateKeyDecrypt(request);
+ case NO -> {
+ }
+ default -> throw new ServiceException("解密失败,不支持的加密算法类型");
}
} catch (ServiceException e) {
throw e;
diff --git a/airpower-core/src/main/java/cn/hamm/airpower/open/OpenResponse.java b/airpower-core/src/main/java/cn/hamm/airpower/open/OpenResponse.java
index 14fe9a9ef24e7e52e2d0c8f2cf299cdd5a45c1c7..06f45e7b9cfd836270f8d07bc1623ae43591fcfb 100644
--- a/airpower-core/src/main/java/cn/hamm/airpower/open/OpenResponse.java
+++ b/airpower-core/src/main/java/cn/hamm/airpower/open/OpenResponse.java
@@ -31,16 +31,15 @@ public class OpenResponse {
);
try {
switch (appArithmeticType) {
- case AES:
- response = Utils.getAesUtil().setKey(openApp.getAppSecret()).encrypt(response);
- break;
- case RSA:
- response = Utils.getRsaUtil().setPrivateKey(openApp.getPrivateKey()).publicKeyEncrypt(response);
- break;
- case NO:
- break;
- default:
- throw new ServiceException(ServiceError.ENCRYPT_DATA_FAIL, "不支持的加密算法");
+ case AES -> response = Utils.getAesUtil()
+ .setKey(openApp.getAppSecret())
+ .encrypt(response);
+ case RSA -> response = Utils.getRsaUtil()
+ .setPrivateKey(openApp.getPrivateKey())
+ .publicKeyEncrypt(response);
+ case NO -> {
+ }
+ default -> throw new ServiceException(ServiceError.ENCRYPT_DATA_FAIL, "不支持的加密算法");
}
} catch (Exception e) {
ServiceError.ENCRYPT_DATA_FAIL.show();
diff --git a/airpower-core/src/main/java/cn/hamm/airpower/util/AesUtil.java b/airpower-core/src/main/java/cn/hamm/airpower/util/AesUtil.java
index 29313149fa5c196f178a260d6f52e31d0778fd8a..89b46cbf2ccb3fea6a62a7d14c2e624030ef839c 100644
--- a/airpower-core/src/main/java/cn/hamm/airpower/util/AesUtil.java
+++ b/airpower-core/src/main/java/cn/hamm/airpower/util/AesUtil.java
@@ -22,8 +22,14 @@ import java.util.Base64;
*/
@Component
public class AesUtil {
+ /**
+ * 密钥长度
+ */
private static final int KEY_SIZE = 256;
+ /**
+ * AES
+ */
private static final String AES = "AES";
/**
@@ -41,6 +47,47 @@ public class AesUtil {
*/
private byte[] iv = "0000000000000000".getBytes(StandardCharsets.UTF_8);
+ /**
+ * 算法
+ */
+ private String algorithm = AES_CBC_PKCS5_PADDING;
+
+ /**
+ * 获取随机密钥
+ *
+ * @return 随机密钥
+ */
+ @Contract(" -> new")
+ public static @NotNull String getRandomKey() {
+ try {
+ KeyGenerator keyGen = KeyGenerator.getInstance(AES);
+ keyGen.init(KEY_SIZE, new SecureRandom());
+ SecretKey aesKey = keyGen.generateKey();
+ byte[] keyBytes = aesKey.getEncoded();
+ return Base64.getEncoder().encodeToString(keyBytes);
+ } catch (NoSuchAlgorithmException e) {
+ throw new ServiceException(e);
+ }
+ }
+
+ /**
+ * 获取随机密钥
+ *
+ * @return 随机密钥
+ */
+ @Contract(" -> new")
+ public static @NotNull String getRandomIv() {
+ try {
+ KeyGenerator keyGen = KeyGenerator.getInstance(AES);
+ keyGen.init(KEY_SIZE / 2, new SecureRandom());
+ SecretKey aesKey = keyGen.generateKey();
+ byte[] keyBytes = aesKey.getEncoded();
+ return Base64.getEncoder().encodeToString(keyBytes);
+ } catch (NoSuchAlgorithmException e) {
+ throw new ServiceException(e);
+ }
+ }
+
/**
* 设置偏移向量
*
@@ -52,11 +99,6 @@ public class AesUtil {
return this;
}
- /**
- * 算法
- */
- private String algorithm = AES_CBC_PKCS5_PADDING;
-
/**
* 设置算法
*
@@ -115,14 +157,9 @@ public class AesUtil {
* @return Cipher
*/
private @NotNull Cipher getCipher(int mode) {
- System.out.println(key.length);
- System.out.println(new String(key));
- System.out.println(iv.length);
- System.out.println(new String(iv));
try {
SecretKeySpec secretKeySpec = new SecretKeySpec(key, AES);
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
-
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(mode, secretKeySpec, ivParameterSpec);
return cipher;
@@ -130,40 +167,4 @@ public class AesUtil {
throw new RuntimeException(e);
}
}
-
- /**
- * 获取随机密钥
- *
- * @return 随机密钥
- */
- @Contract(" -> new")
- public static @NotNull String getRandomKey() {
- try {
- KeyGenerator keyGen = KeyGenerator.getInstance(AES);
- keyGen.init(KEY_SIZE, new SecureRandom());
- SecretKey aesKey = keyGen.generateKey();
- byte[] keyBytes = aesKey.getEncoded();
- return Base64.getEncoder().encodeToString(keyBytes);
- } catch (NoSuchAlgorithmException e) {
- throw new ServiceException(e);
- }
- }
-
- /**
- * 获取随机密钥
- *
- * @return 随机密钥
- */
- @Contract(" -> new")
- public static @NotNull String getRandomIv() {
- try {
- KeyGenerator keyGen = KeyGenerator.getInstance(AES);
- keyGen.init(KEY_SIZE / 2, new SecureRandom());
- SecretKey aesKey = keyGen.generateKey();
- byte[] keyBytes = aesKey.getEncoded();
- return Base64.getEncoder().encodeToString(keyBytes);
- } catch (NoSuchAlgorithmException e) {
- throw new ServiceException(e);
- }
- }
}
diff --git a/airpower-core/src/main/java/cn/hamm/airpower/util/HttpUtil.java b/airpower-core/src/main/java/cn/hamm/airpower/util/HttpUtil.java
index 5ce183eca4156119e94946eb4bee1077e2544297..ecf0a3b23f6daf64d0b2a5f2501c02f60487c501 100644
--- a/airpower-core/src/main/java/cn/hamm/airpower/util/HttpUtil.java
+++ b/airpower-core/src/main/java/cn/hamm/airpower/util/HttpUtil.java
@@ -127,19 +127,12 @@ public class HttpUtil {
this.headers.forEach((key, value) -> requestBuilder.header(key, value.toString()));
HttpRequest.BodyPublisher bodyPublisher = HttpRequest.BodyPublishers.ofString(body);
switch (method) {
- case GET:
- requestBuilder.GET();
- break;
- case POST:
- requestBuilder.POST(bodyPublisher);
- break;
- case PUT:
- requestBuilder.PUT(bodyPublisher);
- break;
- case DELETE:
- requestBuilder.DELETE();
- break;
- default:
+ case GET -> requestBuilder.GET();
+ case POST -> requestBuilder.POST(bodyPublisher);
+ case PUT -> requestBuilder.PUT(bodyPublisher);
+ case DELETE -> requestBuilder.DELETE();
+ default -> {
+ }
}
if (Objects.nonNull(cookies)) {
List cookieList = new ArrayList<>();
diff --git a/airpower-core/src/main/java/cn/hamm/airpower/util/RedisUtil.java b/airpower-core/src/main/java/cn/hamm/airpower/util/RedisUtil.java
index 67707909e3746db3e5c2b2430beb364577d64328..c516808991a33f6a726b6dd1b1fe85bf7acbc173 100644
--- a/airpower-core/src/main/java/cn/hamm/airpower/util/RedisUtil.java
+++ b/airpower-core/src/main/java/cn/hamm/airpower/util/RedisUtil.java
@@ -1,6 +1,7 @@
package cn.hamm.airpower.util;
import cn.hamm.airpower.config.Configs;
+import cn.hamm.airpower.config.Constant;
import cn.hamm.airpower.enums.ServiceError;
import cn.hamm.airpower.model.Json;
import cn.hamm.airpower.root.RootEntity;
@@ -262,6 +263,6 @@ public class RedisUtil {
* @return key
*/
private @NotNull > String getCacheKey(@NotNull E entity) {
- return entity.getClass().getSimpleName() + "_" + entity.getId().toString();
+ return entity.getClass().getSimpleName() + Constant.UNDERLINE + entity.getId().toString();
}
}
\ No newline at end of file
diff --git a/airpower-core/src/main/java/cn/hamm/airpower/util/ReflectUtil.java b/airpower-core/src/main/java/cn/hamm/airpower/util/ReflectUtil.java
index d50816f9941a60012f0557276ba7d6f5c85f8dbd..07caf02eee0cd7496a8701387369f19753b11455 100644
--- a/airpower-core/src/main/java/cn/hamm/airpower/util/ReflectUtil.java
+++ b/airpower-core/src/main/java/cn/hamm/airpower/util/ReflectUtil.java
@@ -21,7 +21,11 @@ import java.lang.invoke.SerializedLambda;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.util.*;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
/**
* 反射工具类
@@ -252,12 +256,10 @@ public class ReflectUtil {
return fieldList;
}
Field[] fields = clazz.getDeclaredFields();
- for (Field field : fields) {
- // 过滤静态属性 或 过滤transient 关键字修饰的属性
- if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers())) {
- fieldList.add(field);
- }
- }
+ // 过滤静态属性 或 过滤transient 关键字修饰的属性
+ fieldList = Arrays.stream(fields)
+ .filter(field -> !Modifier.isStatic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers()))
+ .collect(Collectors.toCollection(LinkedList::new));
if (isTheRootClass(clazz)) {
return fieldList;
}
@@ -275,11 +277,9 @@ public class ReflectUtil {
*/
public final @NotNull List getFieldNameList(@NotNull Class> clazz) {
Field[] fields = clazz.getDeclaredFields();
- List fieldNames = new ArrayList<>();
- for (Field field : fields) {
- fieldNames.add(field.getName());
- }
- return fieldNames;
+ return Arrays.stream(fields)
+ .map(Field::getName)
+ .collect(Collectors.toList());
}
/**
@@ -289,7 +289,9 @@ public class ReflectUtil {
* @return 函数名
*/
public final @NotNull String getLambdaFunctionName(@NotNull IFunction, ?> lambda) {
- return getSerializedLambda(lambda).getImplMethodName().replace(Constant.GET, Constant.EMPTY_STRING);
+ return getSerializedLambda(lambda)
+ .getImplMethodName()
+ .replace(Constant.GET, Constant.EMPTY_STRING);
}
/**
@@ -299,7 +301,9 @@ public class ReflectUtil {
* @return 类名
*/
public final @NotNull String getLambdaClassName(@NotNull IFunction, ?> lambda) {
- return getSerializedLambda(lambda).getImplClass().replaceAll(Constant.SLASH, Constant.DOT);
+ return getSerializedLambda(lambda)
+ .getImplClass()
+ .replaceAll(Constant.SLASH, Constant.DOT);
}
/**
diff --git a/airpower-core/src/main/java/cn/hamm/airpower/util/StringUtil.java b/airpower-core/src/main/java/cn/hamm/airpower/util/StringUtil.java
index 0d388ea95e49c2824b16f27b537db4f06da006ef..1e93e3446c5b8e6cf53edd7d8caee9b6a1f34af8 100644
--- a/airpower-core/src/main/java/cn/hamm/airpower/util/StringUtil.java
+++ b/airpower-core/src/main/java/cn/hamm/airpower/util/StringUtil.java
@@ -7,6 +7,8 @@ import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
+import java.util.stream.IntStream;
+
/**
* 字符串处理类
*
@@ -36,13 +38,13 @@ public class StringUtil {
return text;
}
StringBuilder stringBuilder = new StringBuilder();
- for (int i = 0; i < text.length(); i++) {
+ IntStream.range(0, text.length()).forEach(i -> {
if (i >= head && i <= text.length() - tail - 1) {
stringBuilder.append(symbol);
} else {
stringBuilder.append(text.charAt(i));
}
- }
+ });
return stringBuilder.toString();
}
@@ -103,36 +105,37 @@ public class StringUtil {
@Contract(pure = true)
public final @NotNull String desensitize(@NotNull String valueString, Desensitize.@NotNull Type type, int head, int tail, String symbol) {
switch (type) {
- case CHINESE_NAME:
+ case CHINESE_NAME -> {
head = Math.max(1, head);
tail = Math.max(1, tail);
if (valueString.length() <= head + tail) {
tail = 0;
}
- break;
- case BANK_CARD:
+ }
+ case BANK_CARD -> {
head = Math.max(4, head);
tail = Math.max(4, tail);
- break;
- case ID_CARD:
+ }
+ case ID_CARD -> {
head = Math.max(6, head);
tail = Math.max(4, tail);
- break;
- case MOBILE:
+ }
+ case MOBILE -> {
head = Math.max(3, head);
tail = Math.max(4, tail);
- break;
- case EMAIL:
+ }
+ case EMAIL -> {
head = 2;
tail = 2;
- break;
- case IP_V4:
+ }
+ case IP_V4 -> {
return Utils.getStringUtil().desensitizeIpv4Address(valueString, symbol);
- case ADDRESS:
+ }
+ case ADDRESS -> {
head = Math.max(3, head);
tail = Math.max(0, tail);
- break;
- case TELEPHONE:
+ }
+ case TELEPHONE -> {
//noinspection AlibabaUndefineMagicConstant
if (valueString.length() <= 8) {
head = Math.max(2, head);
@@ -141,12 +144,13 @@ public class StringUtil {
head = Math.max(4, head);
tail = Math.max(4, tail);
}
- break;
- case CAR_NUMBER:
+ }
+ case CAR_NUMBER -> {
head = Math.max(2, head);
tail = Math.max(1, tail);
- break;
- default:
+ }
+ default -> {
+ }
}
return Utils.getStringUtil().replace(valueString, head, tail, symbol);
}
diff --git a/airpower-core/src/main/java/cn/hamm/airpower/util/TaskUtil.java b/airpower-core/src/main/java/cn/hamm/airpower/util/TaskUtil.java
index 13ee5d894351ca12c076f8b050f46a63cc4345d8..fc4adae3390515dcccfb199492d4f7aaa67b0027 100644
--- a/airpower-core/src/main/java/cn/hamm/airpower/util/TaskUtil.java
+++ b/airpower-core/src/main/java/cn/hamm/airpower/util/TaskUtil.java
@@ -24,13 +24,13 @@ public class TaskUtil {
* @apiNote 如需事务处理,可使用 {@link TransactionUtil#run(TransactionUtil.Function)}
*/
public final void run(Runnable runnable, Runnable... moreRunnable) {
- for (Runnable run : getRunnableList(runnable, moreRunnable)) {
+ getRunnableList(runnable, moreRunnable).forEach(run -> {
try {
run.run();
} catch (Exception exception) {
log.error(exception.getMessage(), exception);
}
- }
+ });
}
/**
@@ -41,9 +41,7 @@ public class TaskUtil {
* @apiNote 如需异步事务处理,可在此参数传入的方法中自行调用 {@link TransactionUtil#run(TransactionUtil.Function)}
*/
public final void runAsync(Runnable runnable, Runnable... moreRunnable) {
- for (Runnable run : getRunnableList(runnable, moreRunnable)) {
- new Thread(run).start();
- }
+ getRunnableList(runnable, moreRunnable).forEach(run -> new Thread(run).start());
}
/**
diff --git a/airpower-core/src/main/java/cn/hamm/airpower/util/TokenUtil.java b/airpower-core/src/main/java/cn/hamm/airpower/util/TokenUtil.java
index ecef22d8a576550213aa75ea108199d10a0446dc..8a9232fec1d3b7727bc748998a0a7fdecd6a4012 100644
--- a/airpower-core/src/main/java/cn/hamm/airpower/util/TokenUtil.java
+++ b/airpower-core/src/main/java/cn/hamm/airpower/util/TokenUtil.java
@@ -36,23 +36,28 @@ public class TokenUtil {
* 算法
*/
private static final String HMAC_SHA_256 = "HmacSHA256";
+
/**
* 缺少负载
*/
private static final String PAYLOADS_IS_EMPTY = "没有任何负载数据";
+
/**
* HMAC-SHA-256错误
*/
private static final String HMAC_SHA_256_ERROR = "HMAC-SHA-256发生错误";
+
/**
* Token由3部分组成
*/
private static final int TOKEN_PART_COUNT = 3;
+
/**
* 验证后的Token
*/
private final VerifiedToken verifiedToken;
+
public TokenUtil() {
verifiedToken = new VerifiedToken();
}
diff --git a/airpower-core/src/main/java/cn/hamm/airpower/util/TreeUtil.java b/airpower-core/src/main/java/cn/hamm/airpower/util/TreeUtil.java
index 34102640615ea31495e7c41f3c88af4db9648daa..351f81fad408c274efd97b2eaafb2ef5f6b15bfd 100644
--- a/airpower-core/src/main/java/cn/hamm/airpower/util/TreeUtil.java
+++ b/airpower-core/src/main/java/cn/hamm/airpower/util/TreeUtil.java
@@ -1,5 +1,6 @@
package cn.hamm.airpower.util;
+import cn.hamm.airpower.config.Constant;
import cn.hamm.airpower.interfaces.ITree;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
@@ -21,7 +22,7 @@ public class TreeUtil {
* @return 树结构数组
*/
public final > List buildTreeList(List list) {
- return buildTreeList(list, 0L);
+ return buildTreeList(list, Constant.ZERO_LONG);
}
/**
diff --git a/airpower-core/src/main/java/cn/hamm/airpower/util/ValidateUtil.java b/airpower-core/src/main/java/cn/hamm/airpower/util/ValidateUtil.java
index 77e2eb6bd2cd162d3d66853b1b801348776e6ed8..950a8eaae6847fbbfc106d7892793d923f1253ad 100644
--- a/airpower-core/src/main/java/cn/hamm/airpower/util/ValidateUtil.java
+++ b/airpower-core/src/main/java/cn/hamm/airpower/util/ValidateUtil.java
@@ -24,12 +24,14 @@ import java.util.regex.Pattern;
@Component
public class ValidateUtil {
/**
- * 从工厂获取Validator实例
+ * 验证器实例
*/
private final Validator validator;
ValidateUtil() {
+ // 初始化验证器工厂
try (ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory()) {
+ // 创建验证器实例
validator = validatorFactory.getValidator();
}
}
@@ -183,14 +185,15 @@ public class ValidateUtil {
}
if (actions.length == Constant.ZERO_INT) {
Set> violations = validator.validate(model);
- if (!violations.isEmpty()) {
- ServiceError.PARAM_INVALID.show(violations.iterator().next().getMessage());
+ if (violations.isEmpty()) {
+ return;
}
- return;
+ ServiceError.PARAM_INVALID.show(violations.iterator().next().getMessage());
}
Set> violations = validator.validate(model, actions);
- if (!violations.isEmpty()) {
- ServiceError.PARAM_INVALID.show(violations.iterator().next().getMessage());
+ if (violations.isEmpty()) {
+ return;
}
+ ServiceError.PARAM_INVALID.show(violations.iterator().next().getMessage());
}
}
diff --git a/pom.xml b/pom.xml
index b115b890d90c95541c9488f8dd626fe2e2dead3f..a9f0c54febcbb2bb7f57c2dd772a3e6f3ec30283 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,11 +4,11 @@
4.0.0
cn.hamm
airpower
- 2.0.4
+ 2.0.5
airpower
AirPower is a fast backend development tool based on SpringBoot3 and JPA.
- 2.0.4
+ 2.0.5
UTF-8
UTF-8
UTF-8