项目地址
Apache commons-BeanUtils 类库提供了一系列对 Java Bean 属性进行动态处理的便捷实现,对 Java 原生的 Reflection (java.lang.reflect)、Introspection (java.beans)API 进行了封装;
以下是一些常用的示例:
apache commons-beanutils,可以用于 PO 、VO 、DTO 转换;
BeanUtils.copyProperties(po1, po2);
BeanUtils.copyProperties(po, vo);
apache commons-beanutils,可以用于比较 2 个 Java Bean 对应字段的值是否一直;
boolean result = EqualsBuilder.reflectionEquals(bean1, bean2);
org.springframework.beans.BeanUtils,对 Java 原生 Reflection API 进行了封装;
//创建反射Method对象
Method method = BeanUtils.findDeclaredMethod(invokeClz, methodName, methodParamClz);
//设置全部可访问性
method.setAccessible(true);
//执行方法
Object result = getMethod().invoke(instance, args);
//执行静态方法
Object result = getMethod().invoke(null, args);