对JAVA Bean使用PropertyDescriptor反射调用JAVA方法

对于符合JAVA Bean规范的bean,调用其方法应优先使用java.beans.PropertyDescriptor获取Method进行方法调用,以获得更大的可维护性。

示比例如以下:

NonCopyLogEntity ncl = new NonCopyLogEntity();
for (int i = 0; i < st.length; i++) {
String fieldName = NonCopyLogEntity.fieldPosMap.get(i + 1);
PropertyDescriptor pd = new PropertyDescriptor(fieldName, ncl.getClass());
Method method = pd.getWriteMethod();
method.invoke(ncl, st[i]);
}

參考资源:

1、PropertyDescriptor

上一篇:开源分布式事务中间件Seata使用指南


下一篇:centos7安装 docker