[color=green][size=x-large][b]org.apache.commons.beanutils[/b][/size][/color]
Person person = new Person();
Person person2 = (Person)BeanUtils.cloneBean(person);
// 前提, 这个Map对象的key必须与Bean的属性相对应.
Map map = new HashMap();
map.put("name", "tom");
map.put("age", "20");
// 将map转化为一个Person对象
Person person = new Person();
BeanUtils.populate(person, map);
// 将Person对象转换为Map
Map map = BeanUtils.describe(person);
Person person = new Person();
String name = request.getParameter("name");
String age = request.getParameter("age");
...
person.setName(name);
person.setAge(age);
...
// 利用Map转换为Bean的功能之后:
Person person = new Person();
Enumeration params = request.getParameterNames();
while (params.hasMoreElements()){
String name = (String) params.nextElement();
map.put(name, request.getParameter(name));
}
BeanUtils.populate(person,map);