set
1.获取类的class对象
MeterHistoryExport meterHistoryExport = new MeterHistoryExport();
Class<? extends MeterHistoryExport> aClass = meterHistoryExport.getClass();
String filedName = StrUtil.upperFirst("name");
Method setName = aClass.getMethod("set" + filedName, String.class)
setName.invoke(meterHistoryExport,"张三");
get
MeterHistoryExport meterHistoryExport = new MeterHistoryExport();
Class<? extends MeterHistoryExport> aClass = meterHistoryExport.getClass();
String filedName = StrUtil.upperFirst("name");
Method getName = aClass.getMethod("get" + filedName, String.class)
Object getInvoke = getName.invoke(meterHistoryExport );
ps 实体类要有get,set方法或者有@Data注解