通过获得对象属性名称给对象赋值

// 要给对象赋值的数据
Map jsonMap = (Map) JSONObject.parse(jsonData);

// 获得对象list
List<DiagnosisRelation> diaList = diagnosisRelationService.getAllList();
Method[] method = diagnosisPra.getClass().getDeclaredMethods();

for (int j = 0; j < diaList.size(); j++) {
	String fieldName = "set" + diaList.get(j).getFieldName();
	for (int n = 0; n < method.length; n++) {
		if (method[n].getName().equalsIgnoreCase(fieldName)) {
			method[n].invoke(diagnosisPra, jsonMap.get(String
					.valueOf(diaList.get(j).getDiagnosisRelationId())));
		}
	}
}
 

你可能感兴趣的:(对象)