首页 > 代码库 > Apache Common Beanutil
Apache Common Beanutil
1. add maven
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.2</version>
<scope>compile</scope>
</dependency>
2. 参数赋值取值
PropertyUtils.getSimpleProperty(Object, String)
PropertyUtils.setSimpleProperty(Object, String, Object)
PropertyUtils.getIndexedProperty(Object, String)
PropertyUtils.getIndexedProperty(Object, String, int)
PropertyUtils.setIndexedProperty(Object, String, Object)
PropertyUtils.setIndexedProperty(Object, String, int, Object)
PropertyUtils.getMappedProperty(Object, String)
PropertyUtils.getMappedProperty(Object, String, String)
PropertyUtils.setMappedProperty(Object, String, Object)
PropertyUtils.setMappedProperty(Object, String, String, Object)
3. 嵌套赋值取值
PropertyUtils.getNestedProperty(Object, String)
PropertyUtils.setNestedProperty(Object, String, Object)
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。