首页 > 其他 > 详细

Apache Common Beanutil

时间:2014-06-10 17:11:55      阅读:410      评论:0      收藏:0      [点我收藏+]

1. add maven 

<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.2</version>
<scope>compile</scope>
</dependency>

2. 参数赋值取值

3. 嵌套赋值取值

4.动态bean

  DynaProperty[] props = new DynaProperty[]{

         new DynaProperty("address", java.util.Map.class),
         new DynaProperty("subordinate", mypackage.Employee[].class),
         new DynaProperty("firstName", String.class),
         new DynaProperty("lastName",  String.class)
       };
     BasicDynaClass dynaClass = new BasicDynaClass("employee", null, props);

DynaBean employee = dynaClass.newInstance();
     employee.set("address", new HashMap());
     employee.set("subordinate", new mypackage.Employee[0]);
     employee.set("firstName", "Fred");
     employee.set("lastName", "Flintstone");
MyBean bean = ...;
     DynaBean wrapper = new WrapDynaBean(bean);
     String firstName = wrapper.get("firstName");

LazyDynaBean 动态添加properties

5.类型转换
HttpServletRequest request = ...;
     MyBean bean = ...;
     HashMap map = new HashMap();
     Enumeration names = request.getParameterNames();
     while (names.hasMoreElements()) {
       String name = (String) names.nextElement();
       map.put(name, request.getParameterValues(name));
     }
     BeanUtils.populate(bean, map);

BeanUtils.cloneBean(Object bean)

BeanUtils.copyProperties(Object dest, Object orig)
BeanUtils.copyProperty(Object bean, String name, Object value)
BeanUtils.setProperty(Object bean, String name, Object value)
BeanUtils.getProperty(Object bean, String name)
6. 集合
1. 比较 BeanComparator 

Apache Common Beanutil,布布扣,bubuko.com

Apache Common Beanutil

原文:http://www.cnblogs.com/zeng200103/p/3779589.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!