mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-11-12 18:57:14 +08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d53eaa3c3 | |||
| 4e2096e37d | |||
| 8dcde6b84d | |||
| fd9d2bb370 | |||
| 464b87c9c7 | |||
| 27ce092b79 | |||
| b11013ee80 |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -1,3 +1,15 @@
|
|||||||
|
## [v2.7.4](https://github.com/continew-org/continew-starter/compare/v2.7.3...v2.7.4) (2024-11-18)
|
||||||
|
|
||||||
|
### 💎 功能优化
|
||||||
|
|
||||||
|
- 【core】增加 + 号字符串/字符常量 ([464b87c](https://github.com/continew-org/continew-starter/commit/464b87c9c7789bc142538bc146ecfe4358c12a50))
|
||||||
|
- 【core】移除多余的校验工具类 ([fd9d2bb](https://github.com/continew-org/continew-starter/commit/fd9d2bb370caef4e9f9e3874e113c381ab4e5eb9))
|
||||||
|
|
||||||
|
### 🐛 问题修复
|
||||||
|
|
||||||
|
- 【extension/crud】修复新增响应结构 BaseIdResp 无法被继承问题 ([27ce092](https://github.com/continew-org/continew-starter/commit/27ce092b796a66f1c59d8715cf5648edab9efa65))
|
||||||
|
- 【json/jackson】修复 BaseEnum 反序列化数据类型仅支持数值的问题 ([b11013e](https://github.com/continew-org/continew-starter/commit/b11013ee80cb00022890d950ff7f666909de2082))
|
||||||
|
|
||||||
## [v2.7.3](https://github.com/continew-org/continew-starter/compare/v2.7.2...v2.7.3) (2024-11-15)
|
## [v2.7.3](https://github.com/continew-org/continew-starter/compare/v2.7.2...v2.7.3) (2024-11-15)
|
||||||
|
|
||||||
### ✨ 新特性
|
### ✨ 新特性
|
||||||
|
|||||||
@@ -76,6 +76,16 @@ public class CharConstants {
|
|||||||
*/
|
*/
|
||||||
public static final char DASHED = '-';
|
public static final char DASHED = '-';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加号 {@code '+'}
|
||||||
|
*/
|
||||||
|
public static final char PLUS = '+';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 等号 {@code '='}
|
||||||
|
*/
|
||||||
|
public static final char EQUALS = '=';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 星号 {@code '*'}
|
* 星号 {@code '*'}
|
||||||
*/
|
*/
|
||||||
@@ -146,11 +156,6 @@ public class CharConstants {
|
|||||||
*/
|
*/
|
||||||
public static final char SINGLE_QUOTE = '\'';
|
public static final char SINGLE_QUOTE = '\'';
|
||||||
|
|
||||||
/**
|
|
||||||
* 等号 {@code '='}
|
|
||||||
*/
|
|
||||||
public static final char EQUALS = '=';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 回车符 {@code '\r'}
|
* 回车符 {@code '\r'}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -94,6 +94,16 @@ public class StringConstants {
|
|||||||
*/
|
*/
|
||||||
public static final String DASHED = "-";
|
public static final String DASHED = "-";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加号 {@code "+"}
|
||||||
|
*/
|
||||||
|
public static final String PLUS = "+";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 等号 {@code "="}
|
||||||
|
*/
|
||||||
|
public static final String EQUALS = "=";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 星号 {@code "*"}
|
* 星号 {@code "*"}
|
||||||
*/
|
*/
|
||||||
@@ -164,11 +174,6 @@ public class StringConstants {
|
|||||||
*/
|
*/
|
||||||
public static final String SINGLE_QUOTE = "'";
|
public static final String SINGLE_QUOTE = "'";
|
||||||
|
|
||||||
/**
|
|
||||||
* 等号 {@code "="}
|
|
||||||
*/
|
|
||||||
public static final String EQUALS = "=";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 回车符 {@code "\r"}
|
* 回车符 {@code "\r"}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,204 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
|
||||||
* <p>
|
|
||||||
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.gnu.org/licenses/lgpl.html
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package top.continew.starter.core.util.validate;
|
|
||||||
|
|
||||||
import cn.hutool.core.text.CharSequenceUtil;
|
|
||||||
import top.continew.starter.core.constant.StringConstants;
|
|
||||||
import top.continew.starter.core.exception.BusinessException;
|
|
||||||
|
|
||||||
import java.util.function.BooleanSupplier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 业务参数校验工具类(抛出 500 ServiceException)
|
|
||||||
*
|
|
||||||
* @author Charles7c
|
|
||||||
* @see BusinessException
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public class CheckUtils extends Validator {
|
|
||||||
|
|
||||||
private static final Class<BusinessException> EXCEPTION_TYPE = BusinessException.class;
|
|
||||||
|
|
||||||
private CheckUtils() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不存在,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj 被检测的对象
|
|
||||||
* @param entityName 实体名
|
|
||||||
* @param fieldName 字段名
|
|
||||||
* @param fieldValue 字段值
|
|
||||||
*/
|
|
||||||
public static void throwIfNotExists(Object obj, String entityName, String fieldName, Object fieldValue) {
|
|
||||||
String message = "%s 为 [%s] 的 %s 记录已不存在".formatted(fieldName, fieldValue, CharSequenceUtil
|
|
||||||
.replace(entityName, "DO", StringConstants.EMPTY));
|
|
||||||
throwIfNull(obj, message, EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj 被检测的对象
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfNull(Object obj, String template, Object... params) {
|
|
||||||
throwIfNull(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj 被检测的对象
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfNotNull(Object obj, String template, Object... params) {
|
|
||||||
throwIfNotNull(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果存在,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj 被检测的对象
|
|
||||||
* @param entityName 实体名
|
|
||||||
* @param fieldName 字段名
|
|
||||||
* @param fieldValue 字段值
|
|
||||||
*/
|
|
||||||
public static void throwIfExists(Object obj, String entityName, String fieldName, Object fieldValue) {
|
|
||||||
String message = "%s 为 [%s] 的 %s 记录已存在".formatted(fieldName, fieldValue, entityName);
|
|
||||||
throwIfNotNull(obj, message, EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj 被检测的对象
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfEmpty(Object obj, String template, Object... params) {
|
|
||||||
throwIfEmpty(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj 被检测的对象
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfNotEmpty(Object obj, String template, Object... params) {
|
|
||||||
throwIfNotEmpty(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param str 被检测的字符串
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfBlank(CharSequence str, String template, Object... params) {
|
|
||||||
throwIfBlank(str, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param str 被检测的字符串
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfNotBlank(CharSequence str, String template, Object... params) {
|
|
||||||
throwIfNotBlank(str, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果相同,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj1 要比较的对象1
|
|
||||||
* @param obj2 要比较的对象2
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfEqual(Object obj1, Object obj2, String template, Object... params) {
|
|
||||||
throwIfEqual(obj1, obj2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不相同,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj1 要比较的对象1
|
|
||||||
* @param obj2 要比较的对象2
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfNotEqual(Object obj1, Object obj2, String template, Object... params) {
|
|
||||||
throwIfNotEqual(obj1, obj2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果相同,抛出异常(不区分大小写)
|
|
||||||
*
|
|
||||||
* @param str1 要比较的字符串1
|
|
||||||
* @param str2 要比较的字符串2
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfEqualIgnoreCase(CharSequence str1, CharSequence str2, String template, Object... params) {
|
|
||||||
throwIfEqualIgnoreCase(str1, str2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不相同,抛出异常(不区分大小写)
|
|
||||||
*
|
|
||||||
* @param str1 要比较的字符串1
|
|
||||||
* @param str2 要比较的字符串2
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfNotEqualIgnoreCase(CharSequence str1,
|
|
||||||
CharSequence str2,
|
|
||||||
String template,
|
|
||||||
Object... params) {
|
|
||||||
throwIfNotEqualIgnoreCase(str1, str2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果条件成立,抛出异常
|
|
||||||
*
|
|
||||||
* @param condition 条件
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIf(boolean condition, String template, Object... params) {
|
|
||||||
throwIf(condition, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果条件成立,抛出异常
|
|
||||||
*
|
|
||||||
* @param conditionSupplier 条件
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIf(BooleanSupplier conditionSupplier, String template, Object... params) {
|
|
||||||
throwIf(conditionSupplier, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,176 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
|
||||||
* <p>
|
|
||||||
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.gnu.org/licenses/lgpl.html
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package top.continew.starter.core.util.validate;
|
|
||||||
|
|
||||||
import cn.hutool.core.text.CharSequenceUtil;
|
|
||||||
import top.continew.starter.core.exception.BadRequestException;
|
|
||||||
|
|
||||||
import java.util.function.BooleanSupplier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 基本参数校验工具类(抛出 400 BadRequestException)
|
|
||||||
*
|
|
||||||
* @author Charles7c
|
|
||||||
* @see BadRequestException
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public class ValidationUtils extends Validator {
|
|
||||||
|
|
||||||
private static final Class<BadRequestException> EXCEPTION_TYPE = BadRequestException.class;
|
|
||||||
|
|
||||||
private ValidationUtils() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj 被检测的对象
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfNull(Object obj, String template, Object... params) {
|
|
||||||
throwIfNull(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj 被检测的对象
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfNotNull(Object obj, String template, Object... params) {
|
|
||||||
throwIfNotNull(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj 被检测的对象
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfEmpty(Object obj, String template, Object... params) {
|
|
||||||
throwIfEmpty(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj 被检测的对象
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfNotEmpty(Object obj, String template, Object... params) {
|
|
||||||
throwIfNotEmpty(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param str 被检测的字符串
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfBlank(CharSequence str, String template, Object... params) {
|
|
||||||
throwIfBlank(str, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param str 被检测的字符串
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfNotBlank(CharSequence str, String template, Object... params) {
|
|
||||||
throwIfNotBlank(str, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果相同,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj1 要比较的对象1
|
|
||||||
* @param obj2 要比较的对象2
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfEqual(Object obj1, Object obj2, String template, Object... params) {
|
|
||||||
throwIfEqual(obj1, obj2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不相同,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj1 要比较的对象1
|
|
||||||
* @param obj2 要比较的对象2
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfNotEqual(Object obj1, Object obj2, String template, Object... params) {
|
|
||||||
throwIfNotEqual(obj1, obj2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果相同,抛出异常(不区分大小写)
|
|
||||||
*
|
|
||||||
* @param str1 要比较的字符串1
|
|
||||||
* @param str2 要比较的字符串2
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfEqualIgnoreCase(CharSequence str1, CharSequence str2, String template, Object... params) {
|
|
||||||
throwIfEqualIgnoreCase(str1, str2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不相同,抛出异常(不区分大小写)
|
|
||||||
*
|
|
||||||
* @param str1 要比较的字符串1
|
|
||||||
* @param str2 要比较的字符串2
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIfNotEqualIgnoreCase(CharSequence str1,
|
|
||||||
CharSequence str2,
|
|
||||||
String template,
|
|
||||||
Object... params) {
|
|
||||||
throwIfNotEqualIgnoreCase(str1, str2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果条件成立,抛出异常
|
|
||||||
*
|
|
||||||
* @param condition 条件
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIf(boolean condition, String template, Object... params) {
|
|
||||||
throwIf(condition, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果条件成立,抛出异常
|
|
||||||
*
|
|
||||||
* @param conditionSupplier 条件
|
|
||||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
|
||||||
* @param params 参数值
|
|
||||||
*/
|
|
||||||
public static void throwIf(BooleanSupplier conditionSupplier, String template, Object... params) {
|
|
||||||
throwIf(conditionSupplier, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,218 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
|
||||||
* <p>
|
|
||||||
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.gnu.org/licenses/lgpl.html
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package top.continew.starter.core.util.validate;
|
|
||||||
|
|
||||||
import cn.hutool.core.text.CharSequenceUtil;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
|
||||||
import jakarta.validation.ConstraintViolation;
|
|
||||||
import jakarta.validation.ConstraintViolationException;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.BooleanSupplier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验器
|
|
||||||
*
|
|
||||||
* @author Charles7c
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public class Validator {
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(Validator.class);
|
|
||||||
private static final jakarta.validation.Validator VALIDATOR = SpringUtil
|
|
||||||
.getBean(jakarta.validation.Validator.class);
|
|
||||||
|
|
||||||
protected Validator() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj 被检测的对象
|
|
||||||
* @param message 错误信息
|
|
||||||
* @param exceptionType 异常类型
|
|
||||||
*/
|
|
||||||
protected static void throwIfNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
|
||||||
throwIf(null == obj, message, exceptionType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj 被检测的对象
|
|
||||||
* @param message 错误信息
|
|
||||||
* @param exceptionType 异常类型
|
|
||||||
*/
|
|
||||||
protected static void throwIfNotNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
|
||||||
throwIf(null != obj, message, exceptionType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj 被检测的对象
|
|
||||||
* @param message 错误信息
|
|
||||||
* @param exceptionType 异常类型
|
|
||||||
*/
|
|
||||||
protected static void throwIfEmpty(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
|
||||||
throwIf(ObjectUtil.isEmpty(obj), message, exceptionType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj 被检测的对象
|
|
||||||
* @param message 错误信息
|
|
||||||
* @param exceptionType 异常类型
|
|
||||||
*/
|
|
||||||
protected static void throwIfNotEmpty(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
|
||||||
throwIf(ObjectUtil.isNotEmpty(obj), message, exceptionType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param str 被检测的字符串
|
|
||||||
* @param message 错误信息
|
|
||||||
* @param exceptionType 异常类型
|
|
||||||
*/
|
|
||||||
protected static void throwIfBlank(CharSequence str,
|
|
||||||
String message,
|
|
||||||
Class<? extends RuntimeException> exceptionType) {
|
|
||||||
throwIf(CharSequenceUtil.isBlank(str), message, exceptionType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不为空,抛出异常
|
|
||||||
*
|
|
||||||
* @param str 被检测的字符串
|
|
||||||
* @param message 错误信息
|
|
||||||
* @param exceptionType 异常类型
|
|
||||||
*/
|
|
||||||
protected static void throwIfNotBlank(CharSequence str,
|
|
||||||
String message,
|
|
||||||
Class<? extends RuntimeException> exceptionType) {
|
|
||||||
throwIf(CharSequenceUtil.isNotBlank(str), message, exceptionType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果相同,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj1 要比较的对象1
|
|
||||||
* @param obj2 要比较的对象2
|
|
||||||
* @param message 错误信息
|
|
||||||
* @param exceptionType 异常类型
|
|
||||||
*/
|
|
||||||
protected static void throwIfEqual(Object obj1,
|
|
||||||
Object obj2,
|
|
||||||
String message,
|
|
||||||
Class<? extends RuntimeException> exceptionType) {
|
|
||||||
throwIf(ObjectUtil.equal(obj1, obj2), message, exceptionType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不相同,抛出异常
|
|
||||||
*
|
|
||||||
* @param obj1 要比较的对象1
|
|
||||||
* @param obj2 要比较的对象2
|
|
||||||
* @param message 错误信息
|
|
||||||
* @param exceptionType 异常类型
|
|
||||||
*/
|
|
||||||
protected static void throwIfNotEqual(Object obj1,
|
|
||||||
Object obj2,
|
|
||||||
String message,
|
|
||||||
Class<? extends RuntimeException> exceptionType) {
|
|
||||||
throwIf(ObjectUtil.notEqual(obj1, obj2), message, exceptionType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果相同,抛出异常(不区分大小写)
|
|
||||||
*
|
|
||||||
* @param str1 要比较的字符串1
|
|
||||||
* @param str2 要比较的字符串2
|
|
||||||
* @param message 错误信息
|
|
||||||
* @param exceptionType 异常类型
|
|
||||||
*/
|
|
||||||
protected static void throwIfEqualIgnoreCase(CharSequence str1,
|
|
||||||
CharSequence str2,
|
|
||||||
String message,
|
|
||||||
Class<? extends RuntimeException> exceptionType) {
|
|
||||||
throwIf(CharSequenceUtil.equalsIgnoreCase(str1, str2), message, exceptionType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果不相同,抛出异常(不区分大小写)
|
|
||||||
*
|
|
||||||
* @param str1 要比较的字符串1
|
|
||||||
* @param str2 要比较的字符串2
|
|
||||||
* @param message 错误信息
|
|
||||||
* @param exceptionType 异常类型
|
|
||||||
*/
|
|
||||||
protected static void throwIfNotEqualIgnoreCase(CharSequence str1,
|
|
||||||
CharSequence str2,
|
|
||||||
String message,
|
|
||||||
Class<? extends RuntimeException> exceptionType) {
|
|
||||||
throwIf(!CharSequenceUtil.equalsIgnoreCase(str1, str2), message, exceptionType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果条件成立,抛出异常
|
|
||||||
*
|
|
||||||
* @param condition 条件
|
|
||||||
* @param message 错误信息
|
|
||||||
* @param exceptionType 异常类型
|
|
||||||
*/
|
|
||||||
protected static void throwIf(boolean condition, String message, Class<? extends RuntimeException> exceptionType) {
|
|
||||||
if (condition) {
|
|
||||||
log.error(message);
|
|
||||||
throw ReflectUtil.newInstance(exceptionType, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果条件成立,抛出异常
|
|
||||||
*
|
|
||||||
* @param conditionSupplier 条件
|
|
||||||
* @param message 错误信息
|
|
||||||
* @param exceptionType 异常类型
|
|
||||||
*/
|
|
||||||
protected static void throwIf(BooleanSupplier conditionSupplier,
|
|
||||||
String message,
|
|
||||||
Class<? extends RuntimeException> exceptionType) {
|
|
||||||
if (null != conditionSupplier && conditionSupplier.getAsBoolean()) {
|
|
||||||
log.error(message);
|
|
||||||
throw ReflectUtil.newInstance(exceptionType, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JSR 303 校验
|
|
||||||
*
|
|
||||||
* @param obj 被校验对象
|
|
||||||
* @param groups 分组
|
|
||||||
* @since 2.3.0
|
|
||||||
*/
|
|
||||||
public static void validate(Object obj, Class<?>... groups) {
|
|
||||||
Set<ConstraintViolation<Object>> violations = VALIDATOR.validate(obj, groups);
|
|
||||||
if (!violations.isEmpty()) {
|
|
||||||
throw new ConstraintViolationException(violations);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package top.continew.starter.core.validation.constraints;
|
package top.continew.starter.core.validation.constraints;
|
||||||
|
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.text.CharSequenceUtil;
|
import cn.hutool.core.text.CharSequenceUtil;
|
||||||
import jakarta.validation.ConstraintValidator;
|
import jakarta.validation.ConstraintValidator;
|
||||||
import jakarta.validation.ConstraintValidatorContext;
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
@@ -54,20 +55,20 @@ public class EnumValueValidator implements ConstraintValidator<EnumValue, Object
|
|||||||
}
|
}
|
||||||
// 优先校验 enumValues
|
// 优先校验 enumValues
|
||||||
if (enumValues.length > 0) {
|
if (enumValues.length > 0) {
|
||||||
return Arrays.asList(enumValues).contains(value.toString());
|
return Arrays.asList(enumValues).contains(Convert.toStr(value));
|
||||||
}
|
}
|
||||||
Enum[] enumConstants = enumClass.getEnumConstants();
|
Enum[] enumConstants = enumClass.getEnumConstants();
|
||||||
if (enumConstants.length == 0) {
|
if (enumConstants.length == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (CharSequenceUtil.isBlank(enumMethod)) {
|
if (CharSequenceUtil.isBlank(enumMethod)) {
|
||||||
return findEnumValue(enumConstants, Enum::toString, value.toString());
|
return findEnumValue(enumConstants, Enum::toString, Convert.toStr(value));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// 枚举类指定了方法名,则调用指定方法获取枚举值
|
// 枚举类指定了方法名,则调用指定方法获取枚举值
|
||||||
Method method = enumClass.getMethod(enumMethod);
|
Method method = enumClass.getMethod(enumMethod);
|
||||||
for (Enum enumConstant : enumConstants) {
|
for (Enum enumConstant : enumConstants) {
|
||||||
if (method.invoke(enumConstant).equals(value)) {
|
if (Convert.toStr(method.invoke(enumConstant)).equals(Convert.toStr(value))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,10 @@ package top.continew.starter.data.mp.autoconfigure;
|
|||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusPropertiesCustomizer;
|
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusPropertiesCustomizer;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.inner.*;
|
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- 项目版本号 -->
|
<!-- 项目版本号 -->
|
||||||
<revision>2.7.3</revision>
|
<revision>2.7.4</revision>
|
||||||
<snail-job.version>1.1.2</snail-job.version>
|
<snail-job.version>1.1.2</snail-job.version>
|
||||||
<sa-token.version>1.39.0</sa-token.version>
|
<sa-token.version>1.39.0</sa-token.version>
|
||||||
<just-auth.version>1.16.6</just-auth.version>
|
<just-auth.version>1.16.6</just-auth.version>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
package top.continew.starter.extension.crud.autoconfigure;
|
package top.continew.starter.extension.crud.autoconfigure;
|
||||||
|
|
||||||
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
||||||
import top.continew.starter.core.util.validate.CheckUtils;
|
import top.continew.starter.core.validation.CheckUtils;
|
||||||
import top.continew.starter.extension.crud.annotation.TreeField;
|
import top.continew.starter.extension.crud.annotation.TreeField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import cn.hutool.core.util.ArrayUtil;
|
|||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import top.continew.starter.core.constant.StringConstants;
|
import top.continew.starter.core.constant.StringConstants;
|
||||||
import top.continew.starter.core.util.validate.ValidationUtils;
|
import top.continew.starter.core.validation.ValidationUtils;
|
||||||
import top.continew.starter.data.core.util.SqlInjectionUtils;
|
import top.continew.starter.data.core.util.SqlInjectionUtils;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import java.io.Serial;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求基类
|
* 请求参数基类
|
||||||
*
|
*
|
||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|||||||
@@ -42,27 +42,10 @@ public class BaseIdResp<T extends Serializable> implements Serializable {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseIdResp(final T id) {
|
public BaseIdResp() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseIdResp(final T id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends Serializable> BaseIdRespBuilder<T> builder() {
|
|
||||||
return new BaseIdRespBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class BaseIdRespBuilder<T extends Serializable> {
|
|
||||||
private T id;
|
|
||||||
|
|
||||||
BaseIdRespBuilder() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public BaseIdRespBuilder<T> id(final T id) {
|
|
||||||
this.id = id;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BaseIdResp<T> build() {
|
|
||||||
return new BaseIdResp(this.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import java.io.Serializable;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 响应基类
|
* 响应参数基类
|
||||||
*
|
*
|
||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public BaseIdResp<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody C req) {
|
public BaseIdResp<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody C req) {
|
||||||
this.checkPermission(Api.ADD);
|
this.checkPermission(Api.ADD);
|
||||||
return BaseIdResp.<Long>builder().id(baseService.add(req)).build();
|
return new BaseIdResp<>(baseService.add(req));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -29,12 +29,11 @@ import cn.hutool.extra.spring.SpringUtil;
|
|||||||
import com.mybatisflex.core.paginate.Page;
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.apache.poi.ss.formula.functions.T;
|
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import top.continew.starter.core.constant.StringConstants;
|
import top.continew.starter.core.constant.StringConstants;
|
||||||
import top.continew.starter.core.util.ReflectUtils;
|
import top.continew.starter.core.util.ReflectUtils;
|
||||||
import top.continew.starter.core.util.validate.ValidationUtils;
|
import top.continew.starter.core.validation.ValidationUtils;
|
||||||
import top.continew.starter.data.mf.base.BaseMapper;
|
import top.continew.starter.data.mf.base.BaseMapper;
|
||||||
import top.continew.starter.data.mf.service.impl.ServiceImpl;
|
import top.continew.starter.data.mf.service.impl.ServiceImpl;
|
||||||
import top.continew.starter.data.mf.util.QueryWrapperHelper;
|
import top.continew.starter.data.mf.util.QueryWrapperHelper;
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public BaseIdResp<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody C req) {
|
public BaseIdResp<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody C req) {
|
||||||
this.checkPermission(Api.ADD);
|
this.checkPermission(Api.ADD);
|
||||||
return BaseIdResp.<Long>builder().id(baseService.add(req)).build();
|
return new BaseIdResp<>(baseService.add(req));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ public interface BaseService<L, D, Q, C> {
|
|||||||
/**
|
/**
|
||||||
* 新增
|
* 新增
|
||||||
*
|
*
|
||||||
* @param req 创建信息
|
* @param req 创建参数
|
||||||
* @return 自增 ID
|
* @return 自增 ID
|
||||||
*/
|
*/
|
||||||
Long add(C req);
|
Long add(C req);
|
||||||
@@ -98,7 +98,7 @@ public interface BaseService<L, D, Q, C> {
|
|||||||
/**
|
/**
|
||||||
* 修改
|
* 修改
|
||||||
*
|
*
|
||||||
* @param req 修改信息
|
* @param req 修改参数
|
||||||
* @param id ID
|
* @param id ID
|
||||||
*/
|
*/
|
||||||
void update(C req, Long id);
|
void update(C req, Long id);
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import top.continew.starter.core.constant.StringConstants;
|
import top.continew.starter.core.constant.StringConstants;
|
||||||
import top.continew.starter.core.util.ClassUtils;
|
import top.continew.starter.core.util.ClassUtils;
|
||||||
import top.continew.starter.core.util.ReflectUtils;
|
import top.continew.starter.core.util.ReflectUtils;
|
||||||
import top.continew.starter.core.util.validate.CheckUtils;
|
import top.continew.starter.core.validation.CheckUtils;
|
||||||
import top.continew.starter.core.util.validate.ValidationUtils;
|
import top.continew.starter.core.validation.ValidationUtils;
|
||||||
import top.continew.starter.data.mp.base.BaseMapper;
|
import top.continew.starter.data.mp.base.BaseMapper;
|
||||||
import top.continew.starter.data.mp.service.impl.ServiceImpl;
|
import top.continew.starter.data.mp.service.impl.ServiceImpl;
|
||||||
import top.continew.starter.data.mp.util.QueryWrapperHelper;
|
import top.continew.starter.data.mp.util.QueryWrapperHelper;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package top.continew.starter.json.jackson.serializer;
|
package top.continew.starter.json.jackson.serializer;
|
||||||
|
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.util.ClassUtil;
|
import cn.hutool.core.util.ClassUtil;
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
@@ -26,6 +27,7 @@ import top.continew.starter.core.enums.BaseEnum;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 枚举接口 BaseEnum 反序列化器
|
* 枚举接口 BaseEnum 反序列化器
|
||||||
@@ -66,7 +68,7 @@ public class BaseEnumDeserializer extends JsonDeserializer<BaseEnum> {
|
|||||||
for (Object enumConstant : enumConstants) {
|
for (Object enumConstant : enumConstants) {
|
||||||
if (ClassUtil.isAssignable(BaseEnum.class, fieldTypeClass)) {
|
if (ClassUtil.isAssignable(BaseEnum.class, fieldTypeClass)) {
|
||||||
BaseEnum baseEnum = (BaseEnum)enumConstant;
|
BaseEnum baseEnum = (BaseEnum)enumConstant;
|
||||||
if (baseEnum.getValue().equals(Integer.valueOf(value))) {
|
if (Objects.equals(Convert.toStr(baseEnum.getValue()), Convert.toStr(value))) {
|
||||||
return baseEnum;
|
return baseEnum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
package top.continew.starter.messaging.mail.core;
|
package top.continew.starter.messaging.mail.core;
|
||||||
|
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import top.continew.starter.core.util.validate.ValidationUtils;
|
import top.continew.starter.core.validation.ValidationUtils;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
package top.continew.starter.messaging.mail.core;
|
package top.continew.starter.messaging.mail.core;
|
||||||
|
|
||||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||||
import top.continew.starter.core.util.validate.ValidationUtils;
|
import top.continew.starter.core.validation.ValidationUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邮件配置
|
* 邮件配置
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
|||||||
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
|
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
|
||||||
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
|
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
|
||||||
import top.continew.starter.core.constant.PropertiesConstants;
|
import top.continew.starter.core.constant.PropertiesConstants;
|
||||||
import top.continew.starter.core.util.validate.CheckUtils;
|
import top.continew.starter.core.validation.CheckUtils;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package top.continew.starter.web.autoconfigure.mvc;
|
|||||||
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import top.continew.starter.core.enums.BaseEnum;
|
import top.continew.starter.core.enums.BaseEnum;
|
||||||
import top.continew.starter.core.util.validate.ValidationUtils;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -42,8 +41,6 @@ public class BaseEnumConverter<T extends BaseEnum> implements Converter<String,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T convert(String source) {
|
public T convert(String source) {
|
||||||
T t = enumMap.get(source);
|
return enumMap.get(source);
|
||||||
ValidationUtils.throwIfNull(t, "枚举值非法:{}", source);
|
|
||||||
return t;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user