BeanUtils. copyProperties原理


总结: BeanUtils. copyProperties(b,a);原理:
    1 根据b的属性来
    2 调用原理  a.set+b的属性名(b.get+b的属性名)

下面是实例代码


import org.springframework.beans.BeanUtils;


public class Test {
      
      
       class A {
            String name ;

             public String getName() {
                   return name ;
            }

             public void setName2(String name) {
                   this .name = name;
            }
            
      }
      
       class B {
            String name2 ;

             public String getname2() {
                   return name2 ;
            }

             public void setName(String name) {
                   this .name2 = name;
            }
            
      }
      
       @org.junit. Test
       public void gg() {
            A a = new A();
            B b = new B();
            a.setName2( "aa" );
            b.setName( "bb" );
            BeanUtils. copyProperties(b,a);
            System. out .println(a.getName());
            System. out .println(b.getname2());
            
      }
      

}



你可能感兴趣的:(BeanUtils,copyProperties)