From c813046594b82230cd2cb61622d68a4981096e08 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期一, 02 八月 2021 19:28:41 +0800 Subject: [PATCH] update 日常校验 统一重构到 StringUtils 便于维护扩展 --- ruoyi-common/src/main/java/com/ruoyi/common/utils/reflect/ReflectUtils.java | 13 ++++++------- 1 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/reflect/ReflectUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/reflect/ReflectUtils.java index 78a74b7..749f1ab 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/reflect/ReflectUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/reflect/ReflectUtils.java @@ -4,7 +4,6 @@ import com.ruoyi.common.utils.StringUtils; import java.lang.reflect.Method; -import java.util.List; /** * 鍙嶅皠宸ュ叿绫�. 鎻愪緵璋冪敤getter/setter鏂规硶, 璁块棶绉佹湁鍙橀噺, 璋冪敤绉佹湁鏂规硶, 鑾峰彇娉涘瀷绫诲瀷Class, 琚獳OP杩囩殑鐪熷疄绫荤瓑宸ュ叿鍑芥暟. @@ -26,7 +25,7 @@ public static <E> E invokeGetter(Object obj, String propertyName) { Object object = obj; for (String name : StringUtils.split(propertyName, ".")) { - String getterMethodName = GETTER_PREFIX + StringUtils.upperFirst(name); + String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name); object = invoke(object, getterMethodName); } return (E) object; @@ -38,13 +37,13 @@ */ public static <E> void invokeSetter(Object obj, String propertyName, E value) { Object object = obj; - List<String> names = StringUtils.split(propertyName, "."); - for (int i = 0; i < names.size(); i++) { - if (i < names.size() - 1) { - String getterMethodName = GETTER_PREFIX + StringUtils.upperFirst(names.get(i)); + String[] names = StringUtils.split(propertyName, "."); + for (int i = 0; i < names.length; i++) { + if (i < names.length - 1) { + String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(names[i]); object = invoke(object, getterMethodName); } else { - String setterMethodName = SETTER_PREFIX + StringUtils.upperFirst(names.get(i)); + String setterMethodName = SETTER_PREFIX + StringUtils.capitalize(names[i]); Method method = getMethodByName(object.getClass(), setterMethodName); invoke(object, method, value); } -- Gitblit v1.9.3