feat(validation): 新增校验模块并引入 SpEL Validator 用于复杂校验场景

This commit is contained in:
2025-06-18 20:19:36 +08:00
parent 5a53d953da
commit 5ae5b2602a
31 changed files with 91 additions and 34 deletions

View File

@@ -152,6 +152,7 @@ continew-starter
├─ continew-starter-jsonJSON 模块)
│ └─ continew-starter-json-jackson
├─ continew-starter-api-doc接口文档模块Spring Doc + Knife4j
├─ continew-starter-validation校验模块Hibernate Validator
├─ continew-starter-webWeb 开发模块:包含跨域、全局异常+响应、链路追踪等自动配置)
├─ continew-starter-cache缓存模块
│ ├─ continew-starter-cache-redissonRedisson
@@ -161,7 +162,7 @@ continew-starter
│ ├─ continew-starter-auth-satoken国产轻量认证鉴权
│ └─ continew-starter-auth-justauth第三方登录
├─ continew-starter-data数据访问模块
│ ├─ continew-starter-data-core通用模块)
│ ├─ continew-starter-data-core核心模块)
│ ├─ continew-starter-data-mpMyBatis Plus
│ └─ continew-starter-data-mfMyBatis Flex
├─ continew-starter-security安全模块
@@ -179,11 +180,13 @@ continew-starter
│ ├─ continew-starter-messaging-mail邮件
│ └─ continew-starter-messaging-websocketWebSocket
├─ continew-starter-log日志模块
│ ├─ continew-starter-log-core通用模块)
│ ├─ continew-starter-log-core核心模块)
│ ├─ continew-starter-log-aop基于 AOP 实现)
│ └─ continew-starter-log-interceptor基于拦截器实现Spring Boot Actuator HttpTrace 增强版))
├─ continew-starter-file文件处理模块)
─ continew-starter-file-excelEasy Excel
├─ continew-starter-excelExcel 文件处理模块)
─ continew-starter-excel-core核心模块
│ ├─ continew-starter-excel-fastexcelFastExcel
│ └─ continew-starter-excel-poiPOI
├─ continew-starter-storage存储模块
│ └─ continew-starter-storage-local本地存储
├─ continew-starter-licenseLicense 模块)
@@ -192,13 +195,13 @@ continew-starter
│ └─ continew-starter-license-verifierLicense 校验器)
└─ continew-starter-extension扩展模块
├─ continew-starter-extension-datapermission数据权限模块
│ ├─ continew-starter-extension-datapermission-core通用模块)
│ ├─ continew-starter-extension-datapermission-core核心模块)
│ └─ continew-starter-extension-datapermission-mpMyBatis Plus
├─ continew-starter-extension-tenant多租户模块
│ ├─ continew-starter-extension-tenant-core通用模块)
│ ├─ continew-starter-extension-tenant-core核心模块)
│ └─ continew-starter-extension-tenant-mpMyBatis Plus
└─ continew-starter-extension-crudCRUD 模块)
├─ continew-starter-extension-crud-core通用模块)
├─ continew-starter-extension-crud-core核心模块)
├─ continew-starter-extension-crud-mpMyBatis Plus
└─ continew-starter-extension-crud-mfMyBatis Flex
```

View File

@@ -39,6 +39,13 @@
<version>${revision}</version>
</dependency>
<!-- 校验模块 -->
<dependency>
<groupId>top.continew</groupId>
<artifactId>continew-starter-validation</artifactId>
<version>${revision}</version>
</dependency>
<!-- Web 模块 -->
<dependency>
<groupId>top.continew</groupId>

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.starter.core.validation;
package top.continew.starter.core.util;
import cn.hutool.core.text.CharSequenceUtil;
import top.continew.starter.core.constant.StringConstants;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.starter.core.validation;
package top.continew.starter.core.util;
import cn.hutool.core.text.CharSequenceUtil;
import top.continew.starter.core.exception.BadRequestException;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.starter.core.validation;
package top.continew.starter.core.util;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;

View File

@@ -1,4 +1,3 @@
top.continew.starter.core.autoconfigure.project.ProjectAutoConfiguration
top.continew.starter.core.autoconfigure.ValidatorAutoConfiguration
top.continew.starter.core.autoconfigure.threadpool.ThreadPoolAutoConfiguration
top.continew.starter.core.autoconfigure.threadpool.AsyncAutoConfiguration

View File

@@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Sort;
import top.continew.starter.core.exception.BadRequestException;
import top.continew.starter.core.util.ReflectUtils;
import top.continew.starter.core.validation.ValidationUtils;
import top.continew.starter.core.util.ValidationUtils;
import top.continew.starter.data.core.annotation.Query;
import top.continew.starter.data.core.annotation.QueryIgnore;
import top.continew.starter.data.core.enums.QueryType;

View File

@@ -20,8 +20,8 @@ import cn.hutool.core.util.ClassUtil;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.repository.CrudRepository;
import top.continew.starter.core.util.ReflectUtils;
import top.continew.starter.core.validation.CheckUtils;
import top.continew.starter.data.mp.service.IService;
import top.continew.starter.core.util.CheckUtils;
import java.io.Serializable;
import java.lang.reflect.Field;

View File

@@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Sort;
import top.continew.starter.core.exception.BadRequestException;
import top.continew.starter.core.util.ReflectUtils;
import top.continew.starter.core.validation.ValidationUtils;
import top.continew.starter.core.util.ValidationUtils;
import top.continew.starter.data.core.annotation.Query;
import top.continew.starter.data.core.annotation.QueryIgnore;
import top.continew.starter.data.core.enums.QueryType;

View File

@@ -39,6 +39,7 @@
<aws-crt.version>0.38.5</aws-crt.version>
<thumbnails.version>0.4.20</thumbnails.version>
<graceful-response.version>5.0.5-boot3</graceful-response.version>
<spel-validator.version>0.5.0-beta</spel-validator.version>
<crane4j.version>2.9.0</crane4j.version>
<knife4j.version>4.5.0</knife4j.version>
<tlog.version>1.5.2</tlog.version>
@@ -266,6 +267,13 @@
<version>${graceful-response.version}</version>
</dependency>
<!-- SpEL Validator基于 SpEL 的 jakarta.validation-api 扩展增强包) -->
<dependency>
<groupId>cn.sticki</groupId>
<artifactId>spel-validator-javax</artifactId>
<version>${spel-validator.version}</version>
</dependency>
<!-- Crane4j基于注解的用于完成一切 “根据 A 的 key 值拿到 B再把 B 的属性映射到 A” 这类需求的字段填充框架) -->
<dependency>
<groupId>cn.crane4j</groupId>

View File

@@ -17,7 +17,7 @@
package top.continew.starter.extension.crud.autoconfigure;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import top.continew.starter.core.validation.CheckUtils;
import top.continew.starter.core.util.CheckUtils;
import top.continew.starter.extension.crud.annotation.TreeField;
/**

View File

@@ -21,7 +21,7 @@ import cn.hutool.core.util.ArrayUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.data.domain.Sort;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.validation.ValidationUtils;
import top.continew.starter.core.util.ValidationUtils;
import top.continew.starter.data.core.util.SqlInjectionUtils;
import java.io.Serial;

View File

@@ -33,7 +33,7 @@ import org.springframework.data.domain.Sort;
import org.springframework.transaction.annotation.Transactional;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.ReflectUtils;
import top.continew.starter.core.validation.ValidationUtils;
import top.continew.starter.core.util.ValidationUtils;
import top.continew.starter.data.mf.base.BaseMapper;
import top.continew.starter.data.mf.service.impl.ServiceImpl;
import top.continew.starter.data.mf.util.QueryWrapperHelper;

View File

@@ -37,8 +37,6 @@ import org.springframework.transaction.annotation.Transactional;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.ClassUtils;
import top.continew.starter.core.util.ReflectUtils;
import top.continew.starter.core.validation.CheckUtils;
import top.continew.starter.core.validation.ValidationUtils;
import top.continew.starter.data.mp.mapper.BaseMapper;
import top.continew.starter.data.mp.service.impl.ServiceImpl;
import top.continew.starter.data.mp.util.QueryWrapperHelper;
@@ -52,6 +50,8 @@ import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.excel.util.ExcelUtils;
import top.continew.starter.core.util.CheckUtils;
import top.continew.starter.core.util.ValidationUtils;
import java.lang.reflect.Field;
import java.util.*;

View File

@@ -17,7 +17,7 @@
package top.continew.starter.messaging.mail.core;
import cn.hutool.core.map.MapUtil;
import top.continew.starter.core.validation.ValidationUtils;
import top.continew.starter.core.util.ValidationUtils;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

View File

@@ -17,7 +17,7 @@
package top.continew.starter.messaging.mail.core;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import top.continew.starter.core.validation.ValidationUtils;
import top.continew.starter.core.util.ValidationUtils;
/**
* 邮件配置

View File

@@ -33,7 +33,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
import top.continew.starter.core.constant.PropertiesConstants;
import top.continew.starter.core.validation.CheckUtils;
import top.continew.starter.core.util.CheckUtils;
import java.util.HashMap;
import java.util.List;

View File

@@ -22,6 +22,7 @@
<artifactId>hutool-dfa</artifactId>
</dependency>
<!-- Spring Boot 校验模块Hibernate Validator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>

View File

@@ -17,7 +17,7 @@
package top.continew.starter.storage.manger;
import top.continew.starter.cache.redisson.util.RedisUtils;
import top.continew.starter.core.validation.ValidationUtils;
import top.continew.starter.core.util.ValidationUtils;
import top.continew.starter.storage.constant.StorageConstant;
import top.continew.starter.storage.strategy.StorageStrategy;

View File

@@ -24,8 +24,8 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.DigestUtil;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.exception.BusinessException;
import top.continew.starter.core.validation.CheckUtils;
import top.continew.starter.core.validation.ValidationUtils;
import top.continew.starter.core.util.CheckUtils;
import top.continew.starter.core.util.ValidationUtils;
import top.continew.starter.storage.client.LocalClient;
import top.continew.starter.storage.constant.StorageConstant;
import top.continew.starter.storage.dao.StorageDao;

View File

@@ -36,8 +36,8 @@ import software.amazon.awssdk.transfer.s3.model.Upload;
import software.amazon.awssdk.transfer.s3.progress.LoggingTransferListener;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.exception.BusinessException;
import top.continew.starter.core.validation.CheckUtils;
import top.continew.starter.core.validation.ValidationUtils;
import top.continew.starter.core.util.CheckUtils;
import top.continew.starter.core.util.ValidationUtils;
import top.continew.starter.storage.client.OssClient;
import top.continew.starter.storage.constant.StorageConstant;
import top.continew.starter.storage.dao.StorageDao;

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>top.continew</groupId>
<artifactId>continew-starter</artifactId>
<version>${revision}</version>
</parent>
<artifactId>continew-starter-validation</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>ContiNew Starter 验证模块</description>
<dependencies>
<!-- 核心模块 -->
<dependency>
<groupId>top.continew</groupId>
<artifactId>continew-starter-core</artifactId>
</dependency>
<!-- Spring Boot 校验模块Hibernate Validator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- SpEL Validator基于 SpEL 的 jakarta.validation-api 扩展增强包) -->
<dependency>
<groupId>cn.sticki</groupId>
<artifactId>spel-validator-javax</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.starter.core.autoconfigure;
package top.continew.starter.validation.autoconfigure;
import jakarta.annotation.PostConstruct;
import jakarta.validation.Validator;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.starter.core.validation.constraints;
package top.continew.starter.validation.constraints;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.starter.core.validation.constraints;
package top.continew.starter.validation.constraints;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.text.CharSequenceUtil;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.starter.core.validation.constraints;
package top.continew.starter.validation.constraints;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.starter.core.validation.constraints;
package top.continew.starter.validation.constraints;
import cn.hutool.json.JSONUtil;
import jakarta.validation.ConstraintValidator;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.starter.core.validation.constraints;
package top.continew.starter.validation.constraints;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.starter.core.validation.constraints;
package top.continew.starter.validation.constraints;
import cn.hutool.core.util.PhoneUtil;
import jakarta.validation.ConstraintValidator;

View File

@@ -0,0 +1 @@
top.continew.starter.validation.autoconfigure.ValidatorAutoConfiguration

View File

@@ -38,6 +38,7 @@
<module>continew-starter-core</module>
<module>continew-starter-json</module>
<module>continew-starter-api-doc</module>
<module>continew-starter-validation</module>
<module>continew-starter-web</module>
<module>continew-starter-cache</module>
<module>continew-starter-auth</module>