PropertyUtils.describe方法测试

public class TestPropertyUtils {

public void test(){
//自己随便写两个类
Fffff ff = new Fffff();
ff.setName("fling");
ff.setDescription("ffff");
Lllll ll = new Lllll();
ll.setAge(88);
ll.setFf(ff);
try {
@SuppressWarnings("unchecked")
//将ff的属性和值都set到map中去
Map<String,Object> mapFf = PropertyUtils.describe(ff);
System.out.println(mapFf.get("name"));
@SuppressWarnings("unchecked")
//将ll的属性和值都set到map中去
Map<String,Object> mapLl = PropertyUtils.describe(ll);
System.out.println(((Fffff)mapLl.get("ff")).getName());
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}

public static void main(String[] args){
TestPropertyUtils tt = new TestPropertyUtils();
tt.test();
}
}

引入的包:commons-beanutils-1.7.0.jar,log4j-1.2.13.jar,commons-logging-1.1.jar

你可能感兴趣的:(PropertyUtils.describe方法测试)