, String> multilingualHeader) {
this.multilingualHeader = multilingualHeader;
}
diff --git a/src/main/java/com/imyeyu/spring/util/Redis.java b/src/main/java/com/imyeyu/spring/util/Redis.java
index e65ac89..a9020fd 100644
--- a/src/main/java/com/imyeyu/spring/util/Redis.java
+++ b/src/main/java/com/imyeyu/spring/util/Redis.java
@@ -22,6 +22,8 @@ import java.util.function.Consumer;
* RedisTemplate 功能封装,简化 Redis 操作
* serializer 为该 RedisTemplate 的键的序列化操作,序列化解析器由 {@link AbstractRedisConfig} 提供
*
+ * @param 键类型
+ * @param 值类型
* @author 夜雨
* @version 2021-11-21 09:58
*/
@@ -30,6 +32,12 @@ public class Redis {
private final RedisSerializer serializer;
private final RedisTemplate redis;
+ /**
+ * 创建 Redis 操作封装
+ *
+ * @param redis RedisTemplate 实例
+ * @param serializer 键序列化器
+ */
public Redis(RedisTemplate redis, RedisSerializer serializer) {
this.redis = redis;
this.serializer = serializer;
@@ -47,9 +55,9 @@ public class Redis {
/**
* 加锁
*
- * @param key
- * @param value
- * @param timeoutMS
+ * @param key 键
+ * @param value 值
+ * @param timeoutMS 超时时间毫秒
* @return true 为加锁成功
*/
public boolean lock(K key, V value, long timeoutMS) {
@@ -57,6 +65,11 @@ public class Redis {
return lock != null && lock;
}
+ /**
+ * 释放锁
+ *
+ * @param key 键
+ */
public void releaseLock(K key) {
destroy(key);
}
diff --git a/src/main/java/com/imyeyu/spring/util/RedisSerializers.java b/src/main/java/com/imyeyu/spring/util/RedisSerializers.java
index 0fe258c..73015b7 100644
--- a/src/main/java/com/imyeyu/spring/util/RedisSerializers.java
+++ b/src/main/java/com/imyeyu/spring/util/RedisSerializers.java
@@ -8,11 +8,17 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.nio.charset.StandardCharsets;
/**
+ * Redis 序列化工具
+ *
* @author 夜雨
* @version 2023-07-17 16:20
*/
public class RedisSerializers {
+ /** 工具类禁止实例化 */
+ private RedisSerializers() {
+ }
+
/** 字符串序列化 */
public static final StringRedisSerializer STRING = new StringRedisSerializer();
@@ -76,7 +82,13 @@ public class RedisSerializers {
}
};
- /** Gson 序列化 */
+ /**
+ * Gson 序列化
+ *
+ * @param 数据类型
+ * @param clazz 数据类型
+ * @return Redis 序列化器
+ */
public static RedisSerializer gsonSerializer(Class clazz) {
return new RedisSerializer<>() {
diff --git a/src/main/java/com/imyeyu/spring/util/SQLProvider.java b/src/main/java/com/imyeyu/spring/util/SQLProvider.java
index 13ac490..2602d19 100644
--- a/src/main/java/com/imyeyu/spring/util/SQLProvider.java
+++ b/src/main/java/com/imyeyu/spring/util/SQLProvider.java
@@ -45,6 +45,12 @@ public class SQLProvider {
/** 反射缓存 */
private static final Map, EntityMeta> ENTITY_META_CACHE = new ConcurrentHashMap<>();
+ /**
+ * 创建 SQL 提供器
+ */
+ public SQLProvider() {
+ }
+
/**
* 根据 Page 对象查询数据列表
*
@@ -148,6 +154,12 @@ public class SQLProvider {
return sql.toString();
}
+ /**
+ * 查询全部数据
+ *
+ * @param context 代理器上下文
+ * @return SQL
+ */
public String selectAll(ProviderContext context) {
EntityMeta meta = getEntityMeta(context);
StringBuilder sql = new StringBuilder();
@@ -162,6 +174,7 @@ public class SQLProvider {
* 插入
* 不实现 {@link Creatable} 也允许调用是合理的,某些数据属于关联数据,不参与主创建过程
*
+ * @param context 代理器上下文
* @param entity 实体
* @return SQL
*/
@@ -299,6 +312,12 @@ public class SQLProvider {
return "UPDATE `%s` SET `deleted_at` = %s WHERE `%s` = #{id}".formatted(meta.table, Time.now(), meta.idFieldColumn.columnName);
}
+ /**
+ * 根据示例批量逻辑删除
+ *
+ * @param entity 实体
+ * @return SQL
+ */
public String deleteAllByExample(Object entity) {
EntityMeta meta = getEntityMeta(entity.getClass());
TimiException.required(meta.canDelete, "not allow delete for %s".formatted(meta.entityClass));
@@ -398,6 +417,11 @@ public class SQLProvider {
/** true 为可销毁(硬删除) */
final boolean canDestroy;
+ /**
+ * 创建实体元数据
+ *
+ * @param entityClass 实体类型
+ */
public EntityMeta(Class> entityClass) {
this.entityClass = entityClass;
@@ -459,38 +483,83 @@ public class SQLProvider {
return sb.substring(0, sb.length() - 1);
}
+ /**
+ * 获取实体类型
+ *
+ * @return 实体类型
+ */
public Class> getEntityClass() {
return entityClass;
}
+ /**
+ * 获取表名
+ *
+ * @return 表名
+ */
public String getTable() {
return table;
}
+ /**
+ * 获取查询字段映射
+ *
+ * @return 查询字段映射
+ */
public String getSelectAllClause() {
return selectAllClause;
}
+ /**
+ * 获取 ID 字段映射
+ *
+ * @return ID 字段映射
+ */
public FieldColumn getIdFieldColumn() {
return idFieldColumn;
}
+ /**
+ * 获取字段映射列表
+ *
+ * @return 字段映射列表
+ */
public List getFieldColumnList() {
return fieldColumnList;
}
+ /**
+ * 是否可创建
+ *
+ * @return true 为可创建
+ */
public boolean canCreate() {
return canCreate;
}
+ /**
+ * 是否可更新
+ *
+ * @return true 为可更新
+ */
public boolean canUpdate() {
return canUpdate;
}
+ /**
+ * 是否可删除
+ *
+ * @return true 为可删除
+ */
public boolean canDelete() {
return canDelete;
}
+ /**
+ * 是否可销毁
+ *
+ * @return true 为可销毁
+ */
public boolean canDestroy() {
return canDestroy;
}
@@ -525,6 +594,11 @@ public class SQLProvider {
final DeleteColumn.Type deleteColumnType;
+ /**
+ * 创建字段映射
+ *
+ * @param field 字段
+ */
public FieldColumn(Field field) {
this.field = field;
@@ -551,6 +625,12 @@ public class SQLProvider {
}
}
+ /**
+ * 判断字段值是否为空
+ *
+ * @param entity 实体
+ * @return true 为 null
+ */
public boolean isNull(Object entity) {
try {
return Ref.getFieldValue(entity, field, Object.class) == null;
@@ -559,10 +639,22 @@ public class SQLProvider {
}
}
+ /**
+ * 判断字段值是否非空
+ *
+ * @param entity 实体
+ * @return true 为非 null
+ */
public boolean isNotNull(Object entity) {
return !isNull(entity);
}
+ /**
+ * 判断字段值是否为空
+ *
+ * @param entity 实体
+ * @return true 为空
+ */
public boolean isEmpty(Object entity) {
try {
return TimiJava.isEmpty(Ref.getFieldValue(entity, field, Object.class));
@@ -571,10 +663,22 @@ public class SQLProvider {
}
}
+ /**
+ * 判断字段值是否非空
+ *
+ * @param entity 实体
+ * @return true 为非空
+ */
public boolean isNotEmpty(Object entity) {
return !isEmpty(entity);
}
+ /**
+ * 获取字段字符串值
+ *
+ * @param obj 实体
+ * @return 字符串值
+ */
public String getAsString(Object obj) {
try {
return field.get(obj).toString();
@@ -583,30 +687,65 @@ public class SQLProvider {
}
}
+ /**
+ * 获取字段
+ *
+ * @return 字段
+ */
public Field getField() {
return field;
}
+ /**
+ * 获取字段名
+ *
+ * @return 字段名
+ */
public String getFieldName() {
return fieldName;
}
+ /**
+ * 获取列名
+ *
+ * @return 列名
+ */
public String getColumnName() {
return columnName;
}
+ /**
+ * 是否为 ID 字段
+ *
+ * @return true 为 ID 字段
+ */
public boolean isId() {
return isId;
}
+ /**
+ * 是否非 ID 字段
+ *
+ * @return true 为非 ID 字段
+ */
public boolean isNotId() {
return !isId();
}
+ /**
+ * 是否自动 UUID
+ *
+ * @return true 为自动 UUID
+ */
public boolean isAutoUUID() {
return isAutoUUID;
}
+ /**
+ * 是否自动大写 UUID
+ *
+ * @return true 为自动大写 UUID
+ */
public boolean isAutoUpperUUID() {
return isAutoUpperUUID;
}
diff --git a/src/main/java/com/imyeyu/spring/util/YamlPropertySourceFactory.java b/src/main/java/com/imyeyu/spring/util/YamlPropertySourceFactory.java
index 35f7305..8745a8f 100644
--- a/src/main/java/com/imyeyu/spring/util/YamlPropertySourceFactory.java
+++ b/src/main/java/com/imyeyu/spring/util/YamlPropertySourceFactory.java
@@ -9,13 +9,19 @@ import java.io.IOException;
import java.util.List;
/**
- *
+ * Yaml 属性源加载工厂
*
* @author 夜雨
* @since 2025-10-13 16:29
*/
public class YamlPropertySourceFactory implements PropertySourceFactory {
+ /**
+ * 创建 Yaml 属性源工厂
+ */
+ public YamlPropertySourceFactory() {
+ }
+
@Override
public @org.springframework.lang.NonNull PropertySource> createPropertySource(String name, EncodedResource resource) throws IOException {
List> sources = new YamlPropertySourceLoader().load(resource.getResource().getFilename(), resource.getResource());