码迷,mamicode.com
首页 > 其他好文 > 详细

Apache Common Beanutil

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

标签:des   style   class   code   java   http   

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

标签:des   style   class   code   java   http   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!