---
title: "PropertyUtils.describe方法测试"
author: "everlook"
date: "2012-02-08T09:56:08Z"
tags: []
categories: ["编程语言"]
slug: "propertyutils-describe"
draft: false
lastmod: "2012-02-08T09:56:08Z"
id: 1397395
url: "https://everlook.iteye.com/blog/1397395"
---

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