PropertyUtils和MethodUtils使用
来源:互联网 发布:北大网络教育毕业证 编辑:程序博客网 时间:2024/06/04 18:48
package rong.propertyUtils;
import java.util.Map;
import org.apache.commons.beanutils.MethodUtils;
import org.apache.commons.beanutils.PropertyUtils;
public class TestPropertyUtils {
public static void main(String[] args) throws Exception{
Entity entity = new Entity();
//通过PropertyUtils的getProperty方法获取指定属性的值
Integer id = (Integer)PropertyUtils.getProperty(entity, "id");
String name = (String)PropertyUtils.getProperty(entity, "name");
System.out.println("id = " + id + " name = " + name);
//调用PropertyUtils的setProperty方法设置entity的指定属性
PropertyUtils.setProperty(entity, "name", "心梦帆影");
System.out.println("name = " + entity.getName());
//通过PropertyUtils的describe方法把entity的所有属性与属性值封装进Map中
Map map = PropertyUtils.describe(entity);
System.out.println("id = " + map.get("id") + " name = " + map.get("name"));
//通过MethodUtils的invokeMethod方法,执行指定的entity中的方法(无参的情况)
System.out.println( MethodUtils.invokeMethod(entity, "haha", null) );
//通过MethodUtils的invokeMethod方法,执行指定的entity中的方法(1参的情况)
MethodUtils.invokeMethod(entity, "sayHelle", "心梦帆影");
//通过MethodUtils的invokeMethod方法,执行指定的entity中的方法(多参的情况)
Object[] params = new Object[]{new Integer(10),new Integer(12)};
String msg = (String)MethodUtils.invokeMethod(entity, "countAges", params);
System.out.println(msg);
}
}
- PropertyUtils和MethodUtils使用
- PropertyUtils和MethodUtils使用
- BeanUtils MethodUtils PropertyUtils 的使用
- BeanUtils & PropertyUtils & MethodUtils类使用方法
- BeanUtils & PropertyUtils & MethodUtils类使用方法
- 【转】BeanUtils & PropertyUtils & MethodUtils类使用方法
- BeanUtils & PropertyUtils & MethodUtils类使用方法
- org.apache.commons.beanutils包 BeanUtils、 MethodUtils、 PropertyUtils
- PropertyUtils.copyProperties和BeanUtils.copyProperties使用区别
- PropertyUtils.copyProperties和BeanUtils.copyProperties使用区别
- PropertyUtils的使用
- PropertyUtils的使用
- PropertyUtils的使用
- PropertyUtils的使用
- BeanUtils和PropertyUtils区别
- BeanUtils和PropertyUtils区别
- PropertyUtils
- PropertyUtils.copyProperties()用法和性能
- Oracle Concept 的一些笔记 -- PGA
- 如何执行存储过程以及如何进行调试?
- 索引选择性
- JavaScript --确认对话框confirm
- 使用设计模式构建通用数据库访问类
- PropertyUtils和MethodUtils使用
- ORACLE生成累乘积
- 汉字编码问题
- ORACLE计算累计差
- SSL (Secure Socket Layer)
- 《班级综合管理系统》VB - ACCESS 部分的项目
- MFC 双缓存技术
- Oracle中imp 、exp 命令常用用法
- 数据库复制—— 从SQL Server 2000向SQL Server 2005迁移数据库