Apache Commons BeanUtils
http://commons.apache.org/proper/commons-beanutils/javadocs/v1.9.2/apidocs/org/apache/commons/beanutils/package-summary.html#package_description
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
Apache Commons BeanUtils的更多相关文章
- myeclipse的项目导入到eclipse下,com.sun.org.apache.commons.beanutils.BeanUtils不能导入
com.sun.org.apache.commons.beanutils.BeanUtils这个包不能引入了怎么办自己下了个org.apache.commons的jar包了之后,改成import or ...
- 关闭log4j 输出 DEBUG org.apache.commons.beanutils.*
2016-03-23 10:52:26,860 DEBUG org.apache.commons.beanutils.MethodUtils - Matching name=getEPort on c ...
- Apache Commons Beanutils对象属性批量复制(pseudo-singleton)
Apache Commons Beanutils为开源软件,可在Apache官网http://commons.apache.org/proper/commons-beanutils/download_ ...
- org.apache.commons.beanutils.BeanMap简单使用例子
一.org.apache.commons.beanutils.BeanMap; 将一个java bean允许通过map的api进行调用, 几个支持的操作接口: Object get(Object ke ...
- 对于Java Bean的类型转换问题()使用 org.apache.commons.beanutils.ConvertUtils)
在进行与数据库的交互过程中,由数据库查询到的数据放在 map 中,由 map 到 JavaBean 的过程中可以使用 BeanUtils.populate(map,bean)来进行转换 这里要处理的问 ...
- Apache Commons Beanutils 三 (BeanUtils、ConvertUtils、CollectionUtils...)
前言 前面已经学习了Apache Commons Beanutils包里的PropertyUtils和动态bean,接下来将学习剩下的几个工具类,个人觉得还是非常实用的,特别是CollectionUt ...
- Apache Commons Beanutils 二 (动态Bean - DynaBeans)
相关背景 上一篇介绍了PropertyUtils的用法,PropertyUtils主要是在不修改bean结构的前提下,动态访问bean的属性: 但是有时候,我们会经常希望能够在不定义一个Java类的前 ...
- Apache Commons Beanutils 一 (使用PropertyUtils访问Bean属性)
BeanUtils简要描述 beanutils,顾名思义,是java bean的一个工具类,可以帮助我们方便的读取(get)和设置(set)bean属性值.动态定义和访问bean属性: 细心的话,会发 ...
- org.springframework.beans.BeanUtils与org.apache.commons.beanutils.BeanUtils的copyProperties用法区别
知识点 org.springframework.beans.BeanUtils与org.apache.commons.beanutils.BeanUtils都提供了copyProperties方法,作 ...
随机推荐
- html5,格式的验证
<form action="" method="get"> <input type="text" name=&quo ...
- World Wind .NET开发
World Wind .NET开发
- linux虚拟机上不了网--桥接方式--问题一直未解决
转载的:可是自己的虚拟机就是上不了网,无线网卡该配的也配了还是不行,如果真有台物理机器就行了,省了好多事:但是模拟性能时肯定不行了:有人知道是什么原因不? 虚拟机网络模式 无论是vmware,virt ...
- dd-wrt 定时重连 pppoe 更换ip地址
因为做代理,IP时常被封的原因,所以,需要每天定时重启路由器,重启路由器影响太大,所以重新拨号是一个更好的选择. 在dd-wrt里面,杀掉pppoe服务进程就可以了,这个进程会自动重新启动,然后就相当 ...
- 自定义Chrome插件Vimium
自定义快捷键 map e scrollPageUp map w removeTab map s nextTab map a previousTab map q goNext map z restore ...
- qt qml 刮刮卡效果
用canvas+mouseArea实现的刮刮卡效果. 表层是一层色彩,用手指划开,可看到下面的文字Lisence: MIT, 请保留本文档说明Author: surfsky.cnblogs.com 2 ...
- 安装 whmcs
1.下载下来后(自己百度网盘),用scp 上传, 在网站能访问的地方新建目录,例如 whmcs 目录,解压到内 2.网站访问 http://ip/whmcs/index.php 提示需要安装 ionc ...
- C#转VB.NET
这个不能用了 http://www.developerfusion.com/tools/convert/csharp-to-vb/ 搜索几十分钟才找到另一个桌面版的,不怎么好用! http://www ...
- FTP连接时出现“227 Entering Passive Mode” 的解决方法
今天从公网的服务器连接本地内网的FTP server copy文件时,系统老是提示227 Entering Passive Mode (xxx,xxx,,xxx,xxx,x),很是奇怪,于是上网找资料 ...
- JavaScript 动态脚本
动态脚本,指的是在页面加载时不存在,但将来的某一个时刻通过修改DOM动态添加的脚本. <script type="text/javascript"> function ...