`
everlook
  • 浏览: 111603 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

PropertyUtils.describe方法测试

    博客分类:
  • java
阅读更多
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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics