From 0548faa837acd0d7c0a2fd469b8e4f0789c537bb Mon Sep 17 00:00:00 2001 From: AprilWind <2100166581@qq.com> Date: Tue, 2 Jul 2024 14:49:06 +0800 Subject: [PATCH] =?UTF-8?q?docs=20=E6=96=B0=E5=A2=9E=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/utils/ValidatorUtils.java | 7 +++ .../dromara/common/json/utils/JsonUtils.java | 61 ++++++++++++++++++- .../common/redis/utils/RedisUtils.java | 6 ++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ValidatorUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ValidatorUtils.java index f94f9164..bc9c371e 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ValidatorUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ValidatorUtils.java @@ -18,6 +18,13 @@ public class ValidatorUtils { private static final Validator VALID = SpringUtils.getBean(Validator.class); + /** + * 对给定对象进行参数校验,并根据指定的校验组进行校验 + * + * @param object 要进行校验的对象 + * @param groups 校验组 + * @throws ConstraintViolationException 如果校验不通过,则抛出参数校验异常 + */ public static void validate(T object, Class... groups) { Set> validate = VALID.validate(object, groups); if (!validate.isEmpty()) { diff --git a/ruoyi-common/ruoyi-common-json/src/main/java/org/dromara/common/json/utils/JsonUtils.java b/ruoyi-common/ruoyi-common-json/src/main/java/org/dromara/common/json/utils/JsonUtils.java index 42af8daf..65c2faae 100644 --- a/ruoyi-common/ruoyi-common-json/src/main/java/org/dromara/common/json/utils/JsonUtils.java +++ b/ruoyi-common/ruoyi-common-json/src/main/java/org/dromara/common/json/utils/JsonUtils.java @@ -7,10 +7,10 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.exc.MismatchedInputException; -import org.dromara.common.core.utils.SpringUtils; -import org.dromara.common.core.utils.StringUtils; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.dromara.common.core.utils.SpringUtils; +import org.dromara.common.core.utils.StringUtils; import java.io.IOException; import java.util.ArrayList; @@ -30,6 +30,13 @@ public class JsonUtils { return OBJECT_MAPPER; } + /** + * 将对象转换为JSON格式的字符串 + * + * @param object 要转换的对象 + * @return JSON格式的字符串,如果对象为null,则返回null + * @throws RuntimeException 如果转换过程中发生JSON处理异常,则抛出运行时异常 + */ public static String toJsonString(Object object) { if (ObjectUtil.isNull(object)) { return null; @@ -41,6 +48,15 @@ public class JsonUtils { } } + /** + * 将JSON格式的字符串转换为指定类型的对象 + * + * @param text JSON格式的字符串 + * @param clazz 要转换的目标对象类型 + * @param 目标对象的泛型类型 + * @return 转换后的对象,如果字符串为空则返回null + * @throws RuntimeException 如果转换过程中发生IO异常,则抛出运行时异常 + */ public static T parseObject(String text, Class clazz) { if (StringUtils.isEmpty(text)) { return null; @@ -52,6 +68,15 @@ public class JsonUtils { } } + /** + * 将字节数组转换为指定类型的对象 + * + * @param bytes 字节数组 + * @param clazz 要转换的目标对象类型 + * @param 目标对象的泛型类型 + * @return 转换后的对象,如果字节数组为空则返回null + * @throws RuntimeException 如果转换过程中发生IO异常,则抛出运行时异常 + */ public static T parseObject(byte[] bytes, Class clazz) { if (ArrayUtil.isEmpty(bytes)) { return null; @@ -63,6 +88,15 @@ public class JsonUtils { } } + /** + * 将JSON格式的字符串转换为指定类型的对象,支持复杂类型 + * + * @param text JSON格式的字符串 + * @param typeReference 指定类型的TypeReference对象 + * @param 目标对象的泛型类型 + * @return 转换后的对象,如果字符串为空则返回null + * @throws RuntimeException 如果转换过程中发生IO异常,则抛出运行时异常 + */ public static T parseObject(String text, TypeReference typeReference) { if (StringUtils.isBlank(text)) { return null; @@ -74,6 +108,13 @@ public class JsonUtils { } } + /** + * 将JSON格式的字符串转换为Dict对象 + * + * @param text JSON格式的字符串 + * @return 转换后的Dict对象,如果字符串为空或者不是JSON格式则返回null + * @throws RuntimeException 如果转换过程中发生IO异常,则抛出运行时异常 + */ public static Dict parseMap(String text) { if (StringUtils.isBlank(text)) { return null; @@ -88,6 +129,13 @@ public class JsonUtils { } } + /** + * 将JSON格式的字符串转换为Dict对象的列表 + * + * @param text JSON格式的字符串 + * @return 转换后的Dict对象的列表,如果字符串为空则返回null + * @throws RuntimeException 如果转换过程中发生IO异常,则抛出运行时异常 + */ public static List parseArrayMap(String text) { if (StringUtils.isBlank(text)) { return null; @@ -99,6 +147,15 @@ public class JsonUtils { } } + /** + * 将JSON格式的字符串转换为指定类型对象的列表 + * + * @param text JSON格式的字符串 + * @param clazz 要转换的目标对象类型 + * @param 目标对象的泛型类型 + * @return 转换后的对象的列表,如果字符串为空则返回空列表 + * @throws RuntimeException 如果转换过程中发生IO异常,则抛出运行时异常 + */ public static List parseArray(String text, Class clazz) { if (StringUtils.isEmpty(text)) { return new ArrayList<>(); diff --git a/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/RedisUtils.java b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/RedisUtils.java index 3fc3aac0..67be2fb7 100644 --- a/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/RedisUtils.java +++ b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/RedisUtils.java @@ -65,6 +65,12 @@ public class RedisUtils { consumer.accept(msg); } + /** + * 发布消息到指定的频道 + * + * @param channelKey 通道key + * @param msg 发送数据 + */ public static void publish(String channelKey, T msg) { RTopic topic = CLIENT.getTopic(channelKey); topic.publish(msg);