ITeye博客

PropertyUtils.describe方法测试

everlook · 2012-02-08 09:56 · java · 编程语言 · Markdown

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。