Person p = new Person();
Map<String,Object> map = new HashMap<String,Object>();
map.put("name", "lisi");
map.put("age", 18);
map.put("gender", "male");
BeanUtils.populate(p,map);
动态代理
JDK代理和CGLIB,JDK代理的是接口,CGLIB代理的是类(后续补充)。
jdk代理 代码实现:
interface Foo {
void show();
}
class FooImpl implements Foo {
public void show() {
System.out.println("foo");
}
}
FooImpl foo = new FooImpl();
Foo f = (Foo)Proxy.newProxyInstance(foo.getClass().getClassLoader(), foo.getClass().getInterfaces(),
new InvocationHandler(){
public Object invoke(Object proxy, Method method, Object[] args){
method.invoke(foo,args);
}
});
f.show();