update 日常校验 统一重构到 StringUtils 便于维护扩展

This commit is contained in:
疯狂的狮子li
2021-08-02 19:28:41 +08:00
parent 5740561cd3
commit c813046594
48 changed files with 493 additions and 239 deletions

View File

@ -4,7 +4,6 @@ import cn.hutool.core.util.ReflectUtil;
import com.ruoyi.common.utils.StringUtils;
import java.lang.reflect.Method;
import java.util.List;
/**
* 反射工具类. 提供调用getter/setter方法, 访问私有变量, 调用私有方法, 获取泛型类型Class, 被AOP过的真实类等工具函数.
@ -26,7 +25,7 @@ public class ReflectUtils extends ReflectUtil {
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 class ReflectUtils extends ReflectUtil {
*/
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);
}