From f1208474f771a1c233d7425c8ed13fbaa0d521ac Mon Sep 17 00:00:00 2001 From: baoshiwei <baoshiwei@shlanbao.cn> Date: 星期三, 12 三月 2025 09:35:13 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/5.X' into 5.X --- ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ObjectUtils.java | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 60 insertions(+), 0 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ObjectUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ObjectUtils.java new file mode 100644 index 0000000..93617b0 --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ObjectUtils.java @@ -0,0 +1,60 @@ +package org.dromara.common.core.utils; + +import cn.hutool.core.util.ObjectUtil; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.function.Function; + +/** + * 瀵硅薄宸ュ叿绫� + * + * @author 绉嬭緸鏈瘨 + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ObjectUtils extends ObjectUtil { + + /** + * 濡傛灉瀵硅薄涓嶄负绌猴紝鍒欒幏鍙栧璞′腑鐨勬煇涓瓧娈� ObjectUtils.notNullGetter(user, User::getName); + * + * @param obj 瀵硅薄 + * @param func 鑾峰彇鏂规硶 + * @return 瀵硅薄瀛楁 + */ + public static <T, E> E notNullGetter(T obj, Function<T, E> func) { + if (isNotNull(obj) && isNotNull(func)) { + return func.apply(obj); + } + return null; + } + + /** + * 濡傛灉瀵硅薄涓嶄负绌猴紝鍒欒幏鍙栧璞′腑鐨勬煇涓瓧娈碉紝鍚﹀垯杩斿洖榛樿鍊� + * + * @param obj 瀵硅薄 + * @param func 鑾峰彇鏂规硶 + * @param defaultValue 榛樿鍊� + * @return 瀵硅薄瀛楁 + */ + public static <T, E> E notNullGetter(T obj, Function<T, E> func, E defaultValue) { + if (isNotNull(obj) && isNotNull(func)) { + return func.apply(obj); + } + return defaultValue; + } + + /** + * 濡傛灉鍊间笉涓虹┖锛屽垯杩斿洖鍊硷紝鍚﹀垯杩斿洖榛樿鍊� + * + * @param obj 瀵硅薄 + * @param defaultValue 榛樿鍊� + * @return 瀵硅薄瀛楁 + */ + public static <T> T notNull(T obj, T defaultValue) { + if (isNotNull(obj)) { + return obj; + } + return defaultValue; + } + +} -- Gitblit v1.9.3