|
@@ -37,7 +37,7 @@ public class UploadSettingTest {
|
|
ImportDataVo constant = Objects.requireNonNull(test).get(i);
|
|
ImportDataVo constant = Objects.requireNonNull(test).get(i);
|
|
//判断 如果说 Json 解析出来的 List<T> 中的 sourceId 和传入参数的 sourceId 匹配成功 则开始装配数据
|
|
//判断 如果说 Json 解析出来的 List<T> 中的 sourceId 和传入参数的 sourceId 匹配成功 则开始装配数据
|
|
if (constant.getSourceId().equals(projectImportPatentVO.getSourceId())) {
|
|
if (constant.getSourceId().equals(projectImportPatentVO.getSourceId())) {
|
|
- //装配数据
|
|
|
|
|
|
+ //填充数据
|
|
jsonData = constant.getColumn();
|
|
jsonData = constant.getColumn();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -68,8 +68,6 @@ public class UploadSettingTest {
|
|
|
|
|
|
PatentInstructionText patentInstructionText = new PatentInstructionText();
|
|
PatentInstructionText patentInstructionText = new PatentInstructionText();
|
|
patentInstructionText.setManual(value.toString());
|
|
patentInstructionText.setManual(value.toString());
|
|
- ReflectionUtils.setField(propertyList, uploadParamsVO.getPatentInstructionTextList()
|
|
|
|
- .add(patentInstructionText), value.toString());
|
|
|
|
}
|
|
}
|
|
ReflectionUtils.setField(propertyList, uploadParamsVO, value.toString());
|
|
ReflectionUtils.setField(propertyList, uploadParamsVO, value.toString());
|
|
break;
|
|
break;
|
|
@@ -82,73 +80,102 @@ public class UploadSettingTest {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-// System.out.println(uploadParamsVO.getPatentNo());
|
|
|
|
-// System.out.println(uploadParamsVO.getApplicationDate());
|
|
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
|
- UploadParamsVO obj = new UploadParamsVO();
|
|
|
|
- PatentInstructionText a = new PatentInstructionText();
|
|
|
|
- a.setManual("1");
|
|
|
|
- a.setManualOut("1");
|
|
|
|
- a.setPatentId(1);
|
|
|
|
- List<PatentInstructionText> aa = new ArrayList<>();
|
|
|
|
- aa.add(a);
|
|
|
|
- obj.setPatentInstructionTextList(aa);
|
|
|
|
- List<PatentInstructionText> B = obj.getPatentInstructionTextList();
|
|
|
|
- B.add(a);
|
|
|
|
- B.add(a);
|
|
|
|
- B.add(a);
|
|
|
|
- obj.setPatentInstructionTextList(B);
|
|
|
|
-
|
|
|
|
|
|
+ private static void fillDataToUploadParamsVO(UploadParamsVO uploadParamsVO) {
|
|
|
|
+ //通过反射获取所有属性
|
|
|
|
+ Field[] field = uploadParamsVO.getClass().getDeclaredFields();
|
|
try {
|
|
try {
|
|
- Field[] fields = obj.getClass().getDeclaredFields();
|
|
|
|
- for (Field field : fields) {
|
|
|
|
- if (!field.isAccessible()) {
|
|
|
|
- field.setAccessible(true);
|
|
|
|
- }
|
|
|
|
- if (List.class.isAssignableFrom(field.getType())) {
|
|
|
|
- Method vvv = List.class.getDeclaredMethod("get", int.class);
|
|
|
|
- System.out.println(vvv);
|
|
|
|
- Method m = List.class.getDeclaredMethod("size");
|
|
|
|
- int size = 0;//调用list的size方法,得到list的长度
|
|
|
|
- //size = (Integer) m.invoke(field.get(obj));
|
|
|
|
- System.out.println(size);
|
|
|
|
- Type t = field.getGenericType();
|
|
|
|
- if (t instanceof ParameterizedType) {
|
|
|
|
- ParameterizedType pt = (ParameterizedType) t;
|
|
|
|
- Class clz = (Class) pt.getActualTypeArguments()[0];//得到对象list中实例的类型
|
|
|
|
- System.out.println(clz.getName());//获得List的泛型类型
|
|
|
|
- Field gg = clz.getDeclaredField("manual");
|
|
|
|
- gg.setAccessible(true);
|
|
|
|
- gg.set(obj.getPatentInstructionTextList().get(0).getManual(),"1");
|
|
|
|
- obj.getPatentInstructionTextList().get(0).getId();
|
|
|
|
- System.out.println("1");
|
|
|
|
- //获取集合的第一个对象
|
|
|
|
- for (int i = 0; i < size; i++) {//遍历list,调用get方法,获取list中的对象实例
|
|
|
|
- Method getM = List.class.getDeclaredMethod("get", int.class);
|
|
|
|
- if (!getM.isAccessible()) {
|
|
|
|
- getM.setAccessible(true);
|
|
|
|
|
|
+ //开始进行 属性级别的循环
|
|
|
|
+ for (Field item : field) {
|
|
|
|
+ //获取每一个属性的名称 例: patentAgent 或者 patentRightList 均为属性参数字段
|
|
|
|
+ String name = item.getName();
|
|
|
|
+ //将获取到的名称的首字母进行大写 用于后续获取 get set 方法的时候用
|
|
|
|
+ name = name.substring(0, 1).toUpperCase() + name.substring(1);
|
|
|
|
+ //获取这个属性的类型 目前在UploadParamsVO中只有 对象类型 和 数组类型(List)
|
|
|
|
+ String type = item.getGenericType().toString();
|
|
|
|
+
|
|
|
|
+ //进行属性类型的判断
|
|
|
|
+ //type的样式为:
|
|
|
|
+ // 对象类型: class com/cn.*.*.*.domain/model.自定义类名 (主要是对象类型会有一个 class 加空格)
|
|
|
|
+ // List类型: java.util.List<com/cn.*.*.*.domain/model.自定义类名>
|
|
|
|
+ //如果类型中包含 class 说明该字段类型为对象类型
|
|
|
|
+ if (type.contains("class")) {
|
|
|
|
+ //从类型中获取对象类型的完整名称 (这里的方法是从后向前找到空格第一次出现的位置 做截取 然后再把空格替换没) 完整名称为 com/cn.*.*.*.domain/model.自定义类名
|
|
|
|
+ String path = type.substring(type.lastIndexOf(" ")).replace(" ", "");
|
|
|
|
+ //将
|
|
|
|
+ Object model = Class.forName(path).newInstance();
|
|
|
|
+ //
|
|
|
|
+ Field[] modelField = model.getClass().getDeclaredFields();
|
|
|
|
+ for (Field element : modelField) {
|
|
|
|
+ String modelName = element.getName();
|
|
|
|
+
|
|
|
|
+ modelName = modelName.substring(0, 1).toUpperCase() + modelName.substring(1);
|
|
|
|
+
|
|
|
|
+ Method m = model.getClass().getMethod("get" + modelName);
|
|
|
|
+ if (element.getGenericType().toString().contains("String")) {
|
|
|
|
+ String value = (String) m.invoke(model);
|
|
|
|
+ if (value == null) {
|
|
|
|
+ m = model.getClass().getMethod("set" + modelName, String.class);
|
|
|
|
+ m.invoke(model, "对象类型测试数据");
|
|
|
|
+ }
|
|
|
|
+ } else if (element.getGenericType().toString().contains("Integer")) {
|
|
|
|
+ Integer value = (Integer) m.invoke(model);
|
|
|
|
+ if (value == null) {
|
|
|
|
+ m = model.getClass().getMethod("set" + modelName, Integer.class);
|
|
|
|
+ m.invoke(model, 2);
|
|
}
|
|
}
|
|
- Object list_i_Obj = getM.invoke(field.get(obj), i);
|
|
|
|
- System.out.println(list_i_Obj);
|
|
|
|
- //集合中的每个元素对象
|
|
|
|
- //获取每个对象的cargoNumber属性值
|
|
|
|
- Field cnField = clz.getDeclaredField("cargoNumber");
|
|
|
|
- cnField.setAccessible(true);
|
|
|
|
- Object o = cnField.get(list_i_Obj);//每个元素对象中的cargoNumber值
|
|
|
|
- System.out.println(o.toString());
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ Method m = uploadParamsVO.getClass().getMethod("set" + name, model.getClass());
|
|
|
|
+ m.invoke(uploadParamsVO, model);
|
|
|
|
+ } else if (type.contains("List") && type.contains("<") && type.contains(">")) {
|
|
|
|
+ List<Object> list = new ArrayList<>();
|
|
|
|
+ String path = type.substring(type.lastIndexOf("<")).replace("<", "").replace(">", "");
|
|
|
|
+ Object model = Class.forName(path).newInstance();
|
|
|
|
+ Field[] fieldName = model.getClass().getDeclaredFields();
|
|
|
|
+ for (Field element : fieldName) {
|
|
|
|
+ String fieldNames = element.getName();
|
|
|
|
+ fieldNames = fieldNames.substring(0, 1).toUpperCase() + fieldNames.substring(1);
|
|
|
|
+ String types = element.getGenericType().toString();
|
|
|
|
+ if (types.equals("class java.lang.String")) {
|
|
|
|
+ Method method = model.getClass().getMethod("get" + fieldNames);
|
|
|
|
+ String value = (String) method.invoke(model);
|
|
|
|
+ if (value == null) {
|
|
|
|
+ method = model.getClass().getMethod("set" + fieldNames, String.class);
|
|
|
|
+ method.invoke(model, "列表类型测试数据");
|
|
|
|
+ }
|
|
|
|
+ } else if (types.equals("class java.lang.Integer")) {
|
|
|
|
+ Method method = model.getClass().getMethod("get" + fieldNames);
|
|
|
|
+ Integer value = (Integer) method.invoke(model);
|
|
|
|
+ if (value == null) {
|
|
|
|
+ method = model.getClass().getMethod("set" + fieldNames, Integer.class);
|
|
|
|
+ method.invoke(model, 1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Method m = uploadParamsVO.getClass().getMethod("get" + name);
|
|
|
|
+ list.add(model);
|
|
|
|
+ List value = (List) m.invoke(uploadParamsVO);
|
|
|
|
+ if (value == null) {
|
|
|
|
+ m = uploadParamsVO.getClass().getMethod("set" + name, List.class);
|
|
|
|
+ m.invoke(uploadParamsVO, list);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ UploadParamsVO uploadParamsVO = new UploadParamsVO();
|
|
|
|
+ fillDataToUploadParamsVO(uploadParamsVO);
|
|
|
|
+ System.out.println(uploadParamsVO);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|