org.springframework.beans.BeanUtils

 

        {//拷贝对象的属性
            Hello user1 = new Hello();
            user1.setId(1);
            user1.setName("name");

            Hello user2 = new Hello();
            BeanUtils.copyProperties(user1, user2);
            System.out.println(user2);
        }

        {//实例化某个类
            Hello user = BeanUtils.instantiateClass(Hello.class);//通过反射实例化一个类的对象
            System.out.println(user);
        }

        {//获取指定类的指定方法
            Method declaredMethod = BeanUtils.findDeclaredMethod(Hello.class, "getId");
            System.out.println(declaredMethod.getName());
        }

        {//获取指定方法的参数
            Method declaredMethod = BeanUtils.findDeclaredMethod(Hello.class, "getId");
            PropertyDescriptor propertyForMethod = BeanUtils.findPropertyForMethod(declaredMethod);
            System.out.println(propertyForMethod.getName());
        }

  

posted @ 2023-10-09 13:58  草木物语  阅读(84)  评论(0编辑  收藏  举报